Skip to content

Rollup of 4 pull requests #75549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 15, 2020
28 changes: 20 additions & 8 deletions library/std/src/sys/unix/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,29 @@ impl Timespec {

fn sub_timespec(&self, other: &Timespec) -> Result<Duration, Duration> {
if self >= other {
Ok(if self.t.tv_nsec >= other.t.tv_nsec {
Duration::new(
(self.t.tv_sec - other.t.tv_sec) as u64,
(self.t.tv_nsec - other.t.tv_nsec) as u32,
)
// NOTE(eddyb) two aspects of this `if`-`else` are required for LLVM
// to optimize it into a branchless form (see also #75545):
//
// 1. `self.t.tv_sec - other.t.tv_sec` shows up as a common expression
// in both branches, i.e. the `else` must have its `- 1`
// subtraction after the common one, not interleaved with it
// (it used to be `self.t.tv_sec - 1 - other.t.tv_sec`)
//
// 2. the `Duration::new` call (or any other additional complexity)
// is outside of the `if`-`else`, not duplicated in both branches
//
// Ideally this code could be rearranged such that it more
// directly expresses the lower-cost behavior we want from it.
let (secs, nsec) = if self.t.tv_nsec >= other.t.tv_nsec {
((self.t.tv_sec - other.t.tv_sec) as u64, (self.t.tv_nsec - other.t.tv_nsec) as u32)
} else {
Duration::new(
(self.t.tv_sec - 1 - other.t.tv_sec) as u64,
(
(self.t.tv_sec - other.t.tv_sec - 1) as u64,
self.t.tv_nsec as u32 + (NSEC_PER_SEC as u32) - other.t.tv_nsec as u32,
)
})
};

Ok(Duration::new(secs, nsec))
} else {
match other.sub_timespec(self) {
Ok(d) => Err(d),
Expand Down
24 changes: 16 additions & 8 deletions src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,14 +282,6 @@ impl Step for Llvm {
"LLVM_CONFIG_PATH",
host_bin.join("llvm-config").with_extension(EXE_EXTENSION),
);

if target.contains("netbsd") {
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
} else if target.contains("freebsd") {
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
} else if target.contains("windows") {
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
}
}

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

if target != builder.config.build {
if target.contains("netbsd") {
cfg.define("CMAKE_SYSTEM_NAME", "NetBSD");
} else if target.contains("freebsd") {
cfg.define("CMAKE_SYSTEM_NAME", "FreeBSD");
} else if target.contains("windows") {
cfg.define("CMAKE_SYSTEM_NAME", "Windows");
}
// When cross-compiling we should also set CMAKE_SYSTEM_VERSION, but in
// that case like CMake we cannot easily determine system version either.
//
// Since, the LLVM itself makes rather limited use of version checks in
// CMakeFiles (and then only in tests), and so far no issues have been
// reported, the system version is currently left unset.
}

let sanitize_cc = |cc: &Path| {
if target.contains("msvc") {
OsString::from(cc.to_str().unwrap().replace("\\", "/"))
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_llvm/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl CodegenCx<'ll, 'tcx> {
debug!("get_static: sym={} instance={:?}", sym, instance);

let g = if let Some(def_id) = def_id.as_local() {
let id = self.tcx.hir().as_local_hir_id(def_id);
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let llty = self.layout_of(ty).llvm_type(self);
// FIXME: refactor this to work without accessing the HIR
let (g, attrs) = match self.tcx.hir().get(id) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_codegen_ssa/back/symbol_export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ fn upstream_drop_glue_for_provider<'tcx>(

fn is_unreachable_local_definition_provider(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
if let Some(def_id) = def_id.as_local() {
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().as_local_hir_id(def_id))
!tcx.reachable_set(LOCAL_CRATE).contains(&tcx.hir().local_def_id_to_hir_id(def_id))
} else {
bug!("is_unreachable_local_definition called with non-local DefId: {:?}", def_id)
}
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,6 @@ impl Definitions {
})
}

#[inline]
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> hir::HirId {
self.local_def_id_to_hir_id(def_id)
}

#[inline]
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
self.def_id_to_hir_id[id].unwrap()
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_infer/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ fn msg_span_from_early_bound_and_free_regions(
let sm = tcx.sess.source_map();

let scope = region.free_region_binding_scope(tcx);
let node = tcx.hir().as_local_hir_id(scope.expect_local());
let node = tcx.hir().local_def_id_to_hir_id(scope.expect_local());
let tag = match tcx.hir().find(node) {
Some(Node::Block(_) | Node::Expr(_)) => "body",
Some(Node::Item(it)) => item_scope_tag(&it),
Expand Down Expand Up @@ -1707,7 +1707,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.in_progress_typeck_results
.map(|typeck_results| typeck_results.borrow().hir_owner)
.map(|owner| {
let hir_id = hir.as_local_hir_id(owner);
let hir_id = hir.local_def_id_to_hir_id(owner);
let parent_id = hir.get_parent_item(hir_id);
(
// Parent item could be a `mod`, so we check the HIR before calling:
Expand All @@ -1733,7 +1733,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// Get the `hir::Param` to verify whether it already has any bounds.
// We do this to avoid suggesting code that ends up as `T: 'a'b`,
// instead we suggest `T: 'a + 'b` in that case.
let id = hir.as_local_hir_id(def_id);
let id = hir.local_def_id_to_hir_id(def_id);
let mut has_bounds = false;
if let Node::GenericParam(param) = hir.get(id) {
has_bounds = !param.bounds.is_empty();
Expand Down Expand Up @@ -1786,7 +1786,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
.and_then(|(_, g)| g.params.first())
.and_then(|param| param.def_id.as_local())
.map(|def_id| {
(hir.span(hir.as_local_hir_id(def_id)).shrink_to_lo(), format!("{}, ", new_lt))
(
hir.span(hir.local_def_id_to_hir_id(def_id)).shrink_to_lo(),
format!("{}, ", new_lt),
)
});

let labeled_user_string = match bound_kind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
br: &ty::BoundRegion,
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let hir_id = self.tcx().hir().as_local_hir_id(anon_reg.def_id);
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
let fndecl = match self.tcx().hir().get(hir_id) {
Node::Item(&hir::Item { kind: hir::ItemKind::Fn(ref m, ..), .. })
| Node::TraitItem(&hir::TraitItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
match assoc_item.kind {
ty::AssocKind::Fn => {
let hir = self.tcx().hir();
if let Some(hir_id) = assoc_item.def_id.as_local().map(|id| hir.as_local_hir_id(id))
if let Some(hir_id) =
assoc_item.def_id.as_local().map(|id| hir.local_def_id_to_hir_id(id))
{
if let Some(decl) = hir.fn_decl_by_hir_id(hir_id) {
visitor.visit_fn_decl(decl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
};

let hir = &self.tcx().hir();
let hir_id = hir.as_local_hir_id(id.as_local()?);
let hir_id = hir.local_def_id_to_hir_id(id.as_local()?);
let body_id = hir.maybe_body_owned_by(hir_id)?;
let body = hir.body(body_id);
let owner_id = hir.body_owner(body_id);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDoc {
// reported for missing docs.
let real_trait = trait_ref.path.res.def_id();
if let Some(def_id) = real_trait.as_local() {
let hir_id = cx.tcx.hir().as_local_hir_id(def_id);
let hir_id = cx.tcx.hir().local_def_id_to_hir_id(def_id);
if let Some(Node::Item(item)) = cx.tcx.hir().find(hir_id) {
if let hir::VisibilityKind::Inherited = item.vis.node {
for impl_item_ref in items {
Expand Down Expand Up @@ -614,7 +614,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingDebugImplementations {
cx.tcx.for_each_impl(debug, |d| {
if let Some(ty_def) = cx.tcx.type_of(d).ty_adt_def() {
if let Some(def_id) = ty_def.did.as_local() {
impls.insert(cx.tcx.hir().as_local_hir_id(def_id));
impls.insert(cx.tcx.hir().local_def_id_to_hir_id(def_id));
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn late_lint_mod_pass<'tcx, T: LateLintPass<'tcx>>(
param_env: ty::ParamEnv::empty(),
access_levels,
lint_store: unerased_lint_store(tcx),
last_node_with_lint_attrs: tcx.hir().as_local_hir_id(module_def_id),
last_node_with_lint_attrs: tcx.hir().local_def_id_to_hir_id(module_def_id),
generics: None,
only_module: true,
};
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_metadata/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ impl EncodeContext<'a, 'tcx> {
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};

let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
let enum_vis = &tcx.hir().expect_item(enum_id).vis;

record!(self.tables.kind[def_id] <- EntryKind::Variant(self.lazy(data)));
Expand Down Expand Up @@ -754,7 +754,7 @@ impl EncodeContext<'a, 'tcx> {

// Variant constructors have the same visibility as the parent enums, unless marked as
// non-exhaustive, in which case they are lowered to `pub(crate)`.
let enum_id = tcx.hir().as_local_hir_id(def.did.expect_local());
let enum_id = tcx.hir().local_def_id_to_hir_id(def.did.expect_local());
let enum_vis = &tcx.hir().expect_item(enum_id).vis;
let mut ctor_vis = ty::Visibility::from_hir(enum_vis, enum_id, tcx);
if variant.is_field_list_non_exhaustive() && ctor_vis == ty::Visibility::Public {
Expand Down Expand Up @@ -793,11 +793,11 @@ impl EncodeContext<'a, 'tcx> {
let data = ModData {
reexports: match tcx.module_exports(local_def_id) {
Some(exports) => {
let hir_map = self.tcx.hir();
let hir = self.tcx.hir();
self.lazy(
exports
.iter()
.map(|export| export.map_id(|id| hir_map.as_local_hir_id(id))),
.map(|export| export.map_id(|id| hir.local_def_id_to_hir_id(id))),
)
}
_ => Lazy::empty(),
Expand Down Expand Up @@ -829,7 +829,7 @@ impl EncodeContext<'a, 'tcx> {
let def_id = field.did;
debug!("EncodeContext::encode_field({:?})", def_id);

let variant_id = tcx.hir().as_local_hir_id(variant.def_id.expect_local());
let variant_id = tcx.hir().local_def_id_to_hir_id(variant.def_id.expect_local());
let variant_data = tcx.hir().expect_variant_data(variant_id);

record!(self.tables.kind[def_id] <- EntryKind::Field);
Expand Down Expand Up @@ -857,7 +857,7 @@ impl EncodeContext<'a, 'tcx> {
is_non_exhaustive: variant.is_field_list_non_exhaustive(),
};

let struct_id = tcx.hir().as_local_hir_id(adt_def.did.expect_local());
let struct_id = tcx.hir().local_def_id_to_hir_id(adt_def.did.expect_local());
let struct_vis = &tcx.hir().expect_item(struct_id).vis;
let mut ctor_vis = ty::Visibility::from_hir(struct_vis, struct_id, tcx);
for field in &variant.fields {
Expand Down Expand Up @@ -919,7 +919,7 @@ impl EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_trait_item({:?})", def_id);
let tcx = self.tcx;

let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let ast_item = tcx.hir().expect_trait_item(hir_id);
let trait_item = tcx.associated_item(def_id);

Expand Down Expand Up @@ -1008,7 +1008,7 @@ impl EncodeContext<'a, 'tcx> {
debug!("EncodeContext::encode_info_for_impl_item({:?})", def_id);
let tcx = self.tcx;

let hir_id = self.tcx.hir().as_local_hir_id(def_id.expect_local());
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id.expect_local());
let ast_item = self.tcx.hir().expect_impl_item(hir_id);
let impl_item = self.tcx.associated_item(def_id);

Expand Down Expand Up @@ -1412,7 +1412,7 @@ impl EncodeContext<'a, 'tcx> {

// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
// including on the signature, which is inferred in `typeck.
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
let hir_id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let ty = self.tcx.typeck(def_id).node_type(hir_id);

record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
Expand All @@ -1439,7 +1439,7 @@ impl EncodeContext<'a, 'tcx> {

fn encode_info_for_anon_const(&mut self, def_id: LocalDefId) {
debug!("EncodeContext::encode_info_for_anon_const({:?})", def_id);
let id = self.tcx.hir().as_local_hir_id(def_id);
let id = self.tcx.hir().local_def_id_to_hir_id(def_id);
let body_id = self.tcx.hir().body_owned_by(id);
let const_data = self.encode_rendered_const_for_body(body_id);
let qualifs = self.tcx.mir_const_qualif(def_id);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/dep_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ impl<'tcx> DepContext for TyCtxt<'tcx> {
}

fn def_id_corresponds_to_hir_dep_node(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
def_id == hir_id.owner
}
11 changes: 3 additions & 8 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,6 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.opt_hir_id_to_local_def_id(hir_id)
}

#[inline]
pub fn as_local_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.as_local_hir_id(def_id)
}

#[inline]
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
self.tcx.definitions.local_def_id_to_hir_id(def_id)
Expand Down Expand Up @@ -450,7 +445,7 @@ impl<'hir> Map<'hir> {
}

pub fn get_module(&self, module: LocalDefId) -> (&'hir Mod<'hir>, Span, HirId) {
let hir_id = self.as_local_hir_id(module);
let hir_id = self.local_def_id_to_hir_id(module);
match self.get_entry(hir_id).node {
Node::Item(&Item { span, kind: ItemKind::Mod(ref m), .. }) => (m, span, hir_id),
Node::Crate(item) => (&item.module, item.span, hir_id),
Expand Down Expand Up @@ -483,7 +478,7 @@ impl<'hir> Map<'hir> {
}

pub fn get_if_local(&self, id: DefId) -> Option<Node<'hir>> {
id.as_local().map(|id| self.get(self.as_local_hir_id(id)))
id.as_local().map(|id| self.get(self.local_def_id_to_hir_id(id)))
}

pub fn get_generics(&self, id: DefId) -> Option<&'hir Generics<'hir>> {
Expand Down Expand Up @@ -872,7 +867,7 @@ impl<'hir> Map<'hir> {
}

pub fn span_if_local(&self, id: DefId) -> Option<Span> {
id.as_local().map(|id| self.span(self.as_local_hir_id(id)))
id.as_local().map(|id| self.span(self.local_def_id_to_hir_id(id)))
}

pub fn res_span(&self, res: Res) -> Option<Span> {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_middle/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ impl<'tcx> TyCtxt<'tcx> {
pub fn provide(providers: &mut Providers) {
providers.parent_module_from_def_id = |tcx, id| {
let hir = tcx.hir();
hir.local_def_id(hir.get_module_parent_node(hir.as_local_hir_id(id)))
hir.local_def_id(hir.get_module_parent_node(hir.local_def_id_to_hir_id(id)))
};
providers.hir_crate = |tcx, _| tcx.untracked_crate;
providers.index_hir = map::index_hir;
providers.hir_module_items = |tcx, id| {
let hir = tcx.hir();
let module = hir.as_local_hir_id(id);
let module = hir.local_def_id_to_hir_id(id);
&tcx.untracked_crate.modules[&module]
};
providers.hir_owner = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].signature;
providers.hir_owner_nodes = |tcx, id| tcx.index_hir(LOCAL_CRATE).map[id].with_bodies.as_deref();
providers.fn_arg_names = |tcx, id| {
let hir = tcx.hir();
let hir_id = hir.as_local_hir_id(id.expect_local());
let hir_id = hir.local_def_id_to_hir_id(id.expect_local());
if let Some(body_id) = hir.maybe_body_owned_by(hir_id) {
tcx.arena.alloc_from_iter(hir.body_param_names(body_id))
} else if let Node::TraitItem(&TraitItem {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {

AggregateKind::Closure(def_id, substs) => ty::tls::with(|tcx| {
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let name = if tcx.sess.opts.debugging_opts.span_free_formats {
let substs = tcx.lift(&substs).unwrap();
format!(
Expand Down Expand Up @@ -2162,7 +2162,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {

AggregateKind::Generator(def_id, _, _) => ty::tls::with(|tcx| {
if let Some(def_id) = def_id.as_local() {
let hir_id = tcx.hir().as_local_hir_id(def_id);
let hir_id = tcx.hir().local_def_id_to_hir_id(def_id);
let name = format!("[generator@{:?}]", tcx.hir().span(hir_id));
let mut struct_fmt = fmt.debug_struct(&name);

Expand Down
Loading