Skip to content

Commit 45060c2

Browse files
committed
Auto merge of #75549 - tmandry:rollup-sxjwa0w, r=tmandry
Rollup of 4 pull requests Successful merges: - #75376 (Set CMAKE_SYSTEM_NAME when cross-compiling) - #75448 (merge `as_local_hir_id` with `local_def_id_to_hir_id`) - #75513 (Recover gracefully from `struct` parse errors) - #75545 (std/sys/unix/time: make it easier for LLVM to optimize `Instant` subtraction.) Failed merges: - #75514 (Replaced `log` with `tracing`) r? @ghost
2 parents 668a34e + 29a9462 commit 45060c2

File tree

89 files changed

+281
-271
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+281
-271
lines changed

library/std/src/sys/unix/time.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,29 @@ impl Timespec {
2020

2121
fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> {
2222
if self >= other {
23-
Ok(if self.t.tv_nsec >= other.t.tv_nsec {
24-
Duration::new(
25-
(self.t.tv_sec - other.t.tv_sec) as u64,
26-
(self.t.tv_nsec - other.t.tv_nsec) as u32,
27-
)
23+
// NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM
24+
// to optimize it into a branchless form (see also #75545):
25+
//
26+
// 1. `self.t.tv_sec - other.t.tv_sec` shows up as a common expression
27+
// in both branches, i.e. the `else` must have its `- 1`
28+
// subtraction after the common one, not interleaved with it
29+
// (it used to be `self.t.tv_sec - 1 - other.t.tv_sec`)
30+
//
31+
// 2. the `Duration::new` call (or any other additional complexity)
32+
// is outside of the `if`-`else`, not duplicated in both branches
33+
//
34+
// Ideally this code could be rearranged such that it more
35+
// directly expresses the lower-cost behavior we want from it.
36+
let (secs, nsec) = if self.t.tv_nsec >= other.t.tv_nsec {
37+
((self.t.tv_sec - other.t.tv_sec) as u64, (self.t.tv_nsec - other.t.tv_nsec) as u32)
2838
} else {
29-
Duration::new(
30-
(self.t.tv_sec - 1 - other.t.tv_sec) as u64,
39+
(
40+
(self.t.tv_sec - other.t.tv_sec - 1) as u64,
3141
self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - other.t.tv_nsec as u32,
3242
)
33-
})
43+
};
44+
45+
Ok(Duration::new(secs, nsec))
3446
} else {
3547
match other.sub_timespec(self) {
3648
Ok(d) => Err(d),

src/bootstrap/native.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -282,14 +282,6 @@ impl Step for Llvm {
282282
"LLVM_CONFIG_PATH",
283283
host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
284284
);
285-
286-
if target.contains("netbsd") {
287-
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
288-
} else if target.contains("freebsd") {
289-
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
290-
} else if target.contains("windows") {
291-
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
292-
}
293285
}
294286

295287
if let Some(ref suffix) = builder.config.llvm_version_suffix {
@@ -378,6 +370,22 @@ fn configure_cmake(
378370
}
379371
cfg.target(&target.triple).host(&builder.config.build.triple);
380372

373+
if target != builder.config.build {
374+
if target.contains("netbsd") {
375+
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
376+
} else if target.contains("freebsd") {
377+
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
378+
} else if target.contains("windows") {
379+
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
380+
}
381+
// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in
382+
// that case like CMake we cannot easily determine system version either.
383+
//
384+
// Since, the LLVM itself makes rather limited use of version checks in
385+
// CMakeFiles (and then only in tests), and so far no issues have been
386+
// reported, the system version is currently left unset.
387+
}
388+
381389
let sanitize_cc = |cc: &Path| {
382390
if target.contains("msvc") {
383391
OsString::from(cc.to_str().unwrap().replace("\\", "/"))

src/librustc_codegen_llvm/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl CodegenCx<'ll, 'tcx> {
215215
debug!("get_static: sym={} instance={:?}", sym, instance);
216216

217217
let g = if let Some(def_id) = def_id.as_local() {
218-
let id = self.tcx.hir().as_local_hir_id(def_id);
218+
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
219219
let llty = self.layout_of(ty).llvm_type(self);
220220
// FIXME: refactor this to work without accessing the HIR
221221
let (g, attrs) = match self.tcx.hir().get(id) {

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ fn upstream_drop_glue_for_provider<'tcx>(
361361

362362
fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
363363
if let Some(def_id) = def_id.as_local() {
364-
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id))
364+
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().local_def_id_to_hir_id(def_id))
365365
} else {
366366
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
367367
}

src/librustc_hir/definitions.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,6 @@ impl Definitions {
306306
})
307307
}
308308

309-
#[inline]
310-
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId {
311-
self.local_def_id_to_hir_id(def_id)
312-
}
313-
314309
#[inline]
315310
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
316311
self.def_id_to_hir_id[id].unwrap()

src/librustc_infer/infer/error_reporting/mod.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn msg_span_from_early_bound_and_free_regions(
144144
let sm = tcx.sess.source_map();
145145

146146
let scope = region.free_region_binding_scope(tcx);
147-
let node = tcx.hir().as_local_hir_id(scope.expect_local());
147+
let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local());
148148
let tag = match tcx.hir().find(node) {
149149
Some(Node::Block(_) | Node::Expr(_)) => "body",
150150
Some(Node::Item(it)) => item_scope_tag(&it),
@@ -1707,7 +1707,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17071707
.in_progress_typeck_results
17081708
.map(|typeck_results| typeck_results.borrow().hir_owner)
17091709
.map(|owner| {
1710-
let hir_id = hir.as_local_hir_id(owner);
1710+
let hir_id = hir.local_def_id_to_hir_id(owner);
17111711
let parent_id = hir.get_parent_item(hir_id);
17121712
(
17131713
// Parent item could be a `mod`, so we check the HIR before calling:
@@ -1733,7 +1733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17331733
// Get the `hir::Param` to verify whether it already has any bounds.
17341734
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
17351735
// instead we suggest `T: 'a + 'b` in that case.
1736-
let id = hir.as_local_hir_id(def_id);
1736+
let id = hir.local_def_id_to_hir_id(def_id);
17371737
let mut has_bounds = false;
17381738
if let Node::GenericParam(param) = hir.get(id) {
17391739
has_bounds = !param.bounds.is_empty();
@@ -1786,7 +1786,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
17861786
.and_then(|(_, g)| g.params.first())
17871787
.and_then(|param| param.def_id.as_local())
17881788
.map(|def_id| {
1789-
(hir.span(hir.as_local_hir_id(def_id)).shrink_to_lo(), format!("{}, ", new_lt))
1789+
(
1790+
hir.span(hir.local_def_id_to_hir_id(def_id)).shrink_to_lo(),
1791+
format!("{}, ", new_lt),
1792+
)
17901793
});
17911794

17921795
let labeled_user_string = match bound_kind {

src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2828
br: &ty::BoundRegion,
2929
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
31-
let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id);
31+
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
3232
let fndecl = match self.tcx().hir().get(hir_id) {
3333
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
3434
| Node::TraitItem(&hir::TraitItem {

src/librustc_infer/infer/error_reporting/nice_region_error/trait_impl_difference.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6767
match assoc_item.kind {
6868
ty::AssocKind::Fn => {
6969
let hir = self.tcx().hir();
70-
if let Some(hir_id) = assoc_item.def_id.as_local().map(|id| hir.as_local_hir_id(id))
70+
if let Some(hir_id) =
71+
assoc_item.def_id.as_local().map(|id| hir.local_def_id_to_hir_id(id))
7172
{
7273
if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) {
7374
visitor.visit_fn_decl(decl);

src/librustc_infer/infer/error_reporting/nice_region_error/util.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4949
};
5050

5151
let hir = &self.tcx().hir();
52-
let hir_id = hir.as_local_hir_id(id.as_local()?);
52+
let hir_id = hir.local_def_id_to_hir_id(id.as_local()?);
5353
let body_id = hir.maybe_body_owned_by(hir_id)?;
5454
let body = hir.body(body_id);
5555
let owner_id = hir.body_owner(body_id);

src/librustc_lint/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
440440
// reported for missing docs.
441441
let real_trait = trait_ref.path.res.def_id();
442442
if let Some(def_id) = real_trait.as_local() {
443-
let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
443+
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
444444
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
445445
if let hir::VisibilityKind::Inherited = item.vis.node {
446446
for impl_item_ref in items {
@@ -614,7 +614,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
614614
cx.tcx.for_each_impl(debug, |d| {
615615
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
616616
if let Some(def_id) = ty_def.did.as_local() {
617-
impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
617+
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id));
618618
}
619619
}
620620
});

0 commit comments

Comments
 (0)