Skip to content

Commit

Permalink
Auto merge of rust-lang#71162 - Centril:rollup-jzg6ykc, r=Centril
Browse files Browse the repository at this point in the history
Rollup of 4 pull requests

Successful merges:

 - rust-lang#70891 (unit rvalue, use constant `()` instead of tuple)
 - rust-lang#71030 (rustc_target: Refactor target specifications related to Windows and UEFI)
 - rust-lang#71100 (Miri: expand frame hooks)
 - rust-lang#71116 (Entirely remove `DUMMY_HIR_ID`)

Failed merges:

r? @ghost
  • Loading branch information
bors committed Apr 15, 2020
2 parents 351eefe + 7341cad commit df768c5
Show file tree
Hide file tree
Showing 151 changed files with 1,255 additions and 563 deletions.
23 changes: 10 additions & 13 deletions src/librustc_ast_lowering/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct LoweringContext<'a, 'hir: 'a> {

current_hir_id_owner: Vec<(LocalDefId, u32)>,
item_local_id_counters: NodeMap<u32>,
node_id_to_hir_id: IndexVec<NodeId, hir::HirId>,
node_id_to_hir_id: IndexVec<NodeId, Option<hir::HirId>>,

allow_try_trait: Option<Lrc<[Symbol]>>,
allow_gen_future: Option<Lrc<[Symbol]>>,
Expand Down Expand Up @@ -522,15 +522,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

self.lower_node_id(CRATE_NODE_ID);
debug_assert!(self.node_id_to_hir_id[CRATE_NODE_ID] == hir::CRATE_HIR_ID);
debug_assert!(self.node_id_to_hir_id[CRATE_NODE_ID] == Some(hir::CRATE_HIR_ID));

visit::walk_crate(&mut MiscCollector { lctx: &mut self, hir_id_owner: None }, c);
visit::walk_crate(&mut item::ItemLowerer { lctx: &mut self }, c);

let module = self.lower_mod(&c.module);
let attrs = self.lower_attrs(&c.attrs);
let body_ids = body_ids(&self.bodies);
let proc_macros = c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id]).collect();
let proc_macros =
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();

self.resolver.definitions().init_node_id_to_hir_id_mapping(self.node_id_to_hir_id);

Expand Down Expand Up @@ -571,26 +572,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
ast_node_id: NodeId,
alloc_hir_id: impl FnOnce(&mut Self) -> hir::HirId,
) -> hir::HirId {
if ast_node_id == DUMMY_NODE_ID {
return hir::DUMMY_HIR_ID;
}
assert_ne!(ast_node_id, DUMMY_NODE_ID);

let min_size = ast_node_id.as_usize() + 1;

if min_size > self.node_id_to_hir_id.len() {
self.node_id_to_hir_id.resize(min_size, hir::DUMMY_HIR_ID);
self.node_id_to_hir_id.resize(min_size, None);
}

let existing_hir_id = self.node_id_to_hir_id[ast_node_id];

if existing_hir_id == hir::DUMMY_HIR_ID {
if let Some(existing_hir_id) = self.node_id_to_hir_id[ast_node_id] {
existing_hir_id
} else {
// Generate a new `HirId`.
let hir_id = alloc_hir_id(self);
self.node_id_to_hir_id[ast_node_id] = hir_id;
self.node_id_to_hir_id[ast_node_id] = Some(hir_id);

hir_id
} else {
existing_hir_id
}
}

Expand Down
15 changes: 6 additions & 9 deletions src/librustc_codegen_ssa/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc_session::search_paths::PathKind;
/// need out of the shared crate context before we get rid of it.
use rustc_session::{filesearch, Session};
use rustc_span::symbol::Symbol;
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
use rustc_target::spec::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel};

use super::archive::ArchiveBuilder;
use super::command::Command;
Expand Down Expand Up @@ -182,7 +182,9 @@ fn get_linker(sess: &Session, linker: &Path, flavor: LinkerFlavor) -> Command {
// To comply with the Windows App Certification Kit,
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
let t = &sess.target.target;
if flavor == LinkerFlavor::Msvc && t.target_vendor == "uwp" {
if (flavor == LinkerFlavor::Msvc || flavor == LinkerFlavor::Lld(LldFlavor::Link))
&& t.target_vendor == "uwp"
{
if let Some(ref tool) = msvc_tool {
let original_path = tool.path();
if let Some(ref root_lib_path) = original_path.ancestors().nth(4) {
Expand Down Expand Up @@ -1530,13 +1532,8 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
cmd.debuginfo();

// OBJECT-FILES-NO, AUDIT-ORDER
// We want to, by default, prevent the compiler from accidentally leaking in
// any system libraries, so we may explicitly ask linkers to not link to any
// libraries by default. Note that this does not happen for windows because
// windows pulls in some large number of libraries and I couldn't quite
// figure out which subset we wanted.
//
// This is all naturally configurable via the standard methods as well.
// We want to prevent the compiler from accidentally leaking in any system libraries,
// so by default we tell linkers not to link to any default libraries.
if !sess.opts.cg.default_linker_libraries.unwrap_or(false)
&& sess.target.target.options.no_default_libraries
{
Expand Down
10 changes: 1 addition & 9 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,15 +631,7 @@ impl<'a> Linker for MsvcLinker<'a> {
}

fn no_default_libraries(&mut self) {
// Currently we don't pass the /NODEFAULTLIB flag to the linker on MSVC
// as there's been trouble in the past of linking the C++ standard
// library required by LLVM. This likely needs to happen one day, but
// in general Windows is also a more controlled environment than
// Unix, so it's not necessarily as critical that this be implemented.
//
// Note that there are also some licensing worries about statically
// linking some libraries which require a specific agreement, so it may
// not ever be possible for us to pass this flag.
self.cmd.arg("/NODEFAULTLIB");
}

fn include_path(&mut self, path: &Path) {
Expand Down
24 changes: 18 additions & 6 deletions src/librustc_hir/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
pub use crate::def_id::DefPathHash;
use crate::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
use crate::hir;
use crate::hir_id::DUMMY_HIR_ID;

use rustc_ast::ast;
use rustc_ast::crate_disambiguator::CrateDisambiguator;
Expand Down Expand Up @@ -87,7 +86,7 @@ pub struct Definitions {
node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,

pub(super) node_id_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
pub(super) node_id_to_hir_id: IndexVec<ast::NodeId, Option<hir::HirId>>,
/// The reverse mapping of `node_id_to_hir_id`.
pub(super) hir_id_to_node_id: FxHashMap<hir::HirId, ast::NodeId>,

Expand Down Expand Up @@ -345,8 +344,7 @@ impl Definitions {
#[inline]
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
if let Some(def_id) = def_id.as_local() {
let hir_id = self.local_def_id_to_hir_id(def_id);
if hir_id != DUMMY_HIR_ID { Some(hir_id) } else { None }
Some(self.local_def_id_to_hir_id(def_id))
} else {
None
}
Expand All @@ -359,11 +357,22 @@ impl Definitions {

#[inline]
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
self.node_id_to_hir_id[node_id].unwrap()
}

#[inline]
pub fn opt_node_id_to_hir_id(&self, node_id: ast::NodeId) -> Option<hir::HirId> {
self.node_id_to_hir_id[node_id]
}

#[inline]
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
let node_id = self.def_id_to_node_id[id];
self.node_id_to_hir_id[node_id].unwrap()
}

#[inline]
pub fn opt_local_def_id_to_hir_id(&self, id: LocalDefId) -> Option<hir::HirId> {
let node_id = self.def_id_to_node_id[id];
self.node_id_to_hir_id[node_id]
}
Expand Down Expand Up @@ -470,7 +479,10 @@ impl Definitions {

/// Initializes the `ast::NodeId` to `HirId` mapping once it has been generated during
/// AST to HIR lowering.
pub fn init_node_id_to_hir_id_mapping(&mut self, mapping: IndexVec<ast::NodeId, hir::HirId>) {
pub fn init_node_id_to_hir_id_mapping(
&mut self,
mapping: IndexVec<ast::NodeId, Option<hir::HirId>>,
) {
assert!(
self.node_id_to_hir_id.is_empty(),
"trying to initialize `NodeId` -> `HirId` mapping twice"
Expand All @@ -481,7 +493,7 @@ impl Definitions {
self.hir_id_to_node_id = self
.node_id_to_hir_id
.iter_enumerated()
.map(|(node_id, &hir_id)| (hir_id, node_id))
.filter_map(|(node_id, &hir_id)| hir_id.map(|hir_id| (hir_id, node_id)))
.collect();
}

Expand Down
3 changes: 0 additions & 3 deletions src/librustc_hir/hir_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,4 @@ pub const CRATE_HIR_ID: HirId = HirId {
local_id: ItemLocalId::from_u32(0),
};

pub const DUMMY_HIR_ID: HirId =
HirId { owner: LocalDefId { local_def_index: CRATE_DEF_INDEX }, local_id: DUMMY_ITEM_LOCAL_ID };

pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;
9 changes: 1 addition & 8 deletions src/librustc_middle/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,16 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
None => format!("{:?}", node),
};

let forgot_str = if hir_id == hir::DUMMY_HIR_ID {
format!("\nMaybe you forgot to lower the node id {:?}?", node_id)
} else {
String::new()
};

span_bug!(
span,
"inconsistent DepNode at `{:?}` for `{}`: \
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
self.source_map.span_to_string(span),
node_str,
self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(),
self.current_dep_node_owner,
self.definitions.def_path(hir_id.owner).to_string_no_crate(),
hir_id.owner,
forgot_str,
)
}
}
Expand Down
10 changes: 10 additions & 0 deletions src/librustc_middle/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,21 @@ impl<'hir> Map<'hir> {
self.tcx.definitions.node_id_to_hir_id(node_id)
}

#[inline]
pub fn opt_node_id_to_hir_id(&self, node_id: NodeId) -> Option<HirId> {
self.tcx.definitions.opt_node_id_to_hir_id(node_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)
}

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

pub fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
let node = self.find(hir_id)?;

Expand Down
16 changes: 2 additions & 14 deletions src/librustc_middle/middle/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ fn late_report_deprecation(
suggestion: Option<Symbol>,
lint: &'static Lint,
span: Span,
def_id: DefId,
hir_id: HirId,
) {
if span.in_derive_expansion() {
Expand All @@ -229,9 +228,6 @@ fn late_report_deprecation(
}
diag.emit()
});
if hir_id == hir::DUMMY_HIR_ID {
span_bug!(span, "emitted a {} lint with dummy HIR id: {:?}", lint.name, def_id);
}
}

/// Result of `TyCtxt::eval_stability`.
Expand Down Expand Up @@ -296,7 +292,7 @@ impl<'tcx> TyCtxt<'tcx> {
if !skip {
let (message, lint) =
deprecation_message(&depr_entry.attr, &self.def_path_str(def_id));
late_report_deprecation(self, &message, None, lint, span, def_id, id);
late_report_deprecation(self, &message, None, lint, span, id);
}
};
}
Expand All @@ -319,15 +315,7 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(depr) = &stability.rustc_depr {
let (message, lint) =
rustc_deprecation_message(depr, &self.def_path_str(def_id));
late_report_deprecation(
self,
&message,
depr.suggestion,
lint,
span,
def_id,
id,
);
late_report_deprecation(self, &message, depr.suggestion, lint, span, id);
}
}
}
Expand Down
17 changes: 10 additions & 7 deletions src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1126,13 +1126,16 @@ impl<'tcx> TyCtxt<'tcx> {

let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
for (k, v) in resolutions.trait_map {
let hir_id = definitions.node_id_to_hir_id(k);
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
// FIXME(#71104) Should really be using just `node_id_to_hir_id` but
// some `NodeId` do not seem to have a corresponding HirId.
if let Some(hir_id) = definitions.opt_node_id_to_hir_id(k) {
let map = trait_map.entry(hir_id.owner).or_default();
let v = v
.into_iter()
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
.collect();
map.insert(hir_id.local_id, StableVec::new(v));
}
}

GlobalCtxt {
Expand Down
41 changes: 22 additions & 19 deletions src/librustc_mir/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::{error_to_const_error, CompileTimeEvalContext, CompileTimeInterpreter, MemoryExtra};
use crate::interpret::eval_nullary_intrinsic;
use crate::interpret::{
intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, ImmTy, Immediate, InternKind,
intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, Immediate, InternKind,
InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RawConst, RefTracking, Scalar,
ScalarMaybeUndef, StackPopCleanup,
};
Expand Down Expand Up @@ -147,25 +147,28 @@ pub(super) fn op_to_const<'tcx>(
match immediate {
Ok(mplace) => to_const_value(mplace),
// see comment on `let try_as_immediate` above
Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x {
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
Err(imm) => match *imm {
Immediate::Scalar(x) => match x {
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
},
Immediate::ScalarPair(a, b) => {
let (data, start) = match a.not_undef().unwrap() {
Scalar::Ptr(ptr) => {
(ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id), ptr.offset.bytes())
}
Scalar::Raw { .. } => (
ecx.tcx
.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"" as &[u8])),
0,
),
};
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
let start = start.try_into().unwrap();
let len: usize = len.try_into().unwrap();
ConstValue::Slice { data, start, end: start + len }
}
},
Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => {
let (data, start) = match a.not_undef().unwrap() {
Scalar::Ptr(ptr) => {
(ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id), ptr.offset.bytes())
}
Scalar::Raw { .. } => (
ecx.tcx.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"" as &[u8])),
0,
),
};
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
let start = start.try_into().unwrap();
let len: usize = len.try_into().unwrap();
ConstValue::Slice { data, start, end: start + len }
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions src/librustc_mir/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use rustc_middle::mir::AssertMessage;
use rustc_span::symbol::Symbol;

use crate::interpret::{
self, AllocId, Allocation, GlobalId, ImmTy, InterpCx, InterpResult, Memory, MemoryKind, OpTy,
PlaceTy, Pointer, Scalar,
self, AllocId, Allocation, Frame, GlobalId, ImmTy, InterpCx, InterpResult, Memory, MemoryKind,
OpTy, PlaceTy, Pointer, Scalar,
};

use super::error::*;
Expand Down Expand Up @@ -342,8 +342,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter {
}

#[inline(always)]
fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
Ok(())
fn init_frame_extra(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
frame: Frame<'mir, 'tcx>,
) -> InterpResult<'tcx, Frame<'mir, 'tcx>> {
Ok(frame)
}

fn before_access_global(
Expand Down
Loading

0 comments on commit df768c5

Please sign in to comment.