Skip to content
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

Rollup of 5 pull requests #71161

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
187f270
Do not ICE in the face of invalid enum discriminant
estebank Mar 10, 2020
1a3bda6
Miri: let push_frame hook also access and mutate the rest of the fram…
RalfJung Apr 13, 2020
7b90ff9
add after_stack_push hook; add public ImmTy::from_immediate method, a…
RalfJung Apr 13, 2020
3ad8c88
rustc_target: Make sure lld-link is treated as link.exe by default
petrochenkov Apr 10, 2020
7a4f059
rustc_target: Move tests into a separate unconfigured file
petrochenkov Apr 11, 2020
cfe90eb
linker: Pass `/NODEFAULTLIB` in a more regular way
petrochenkov Apr 11, 2020
6580ceb
rustc_target: `windows(_uwp)_base` -> `windows(_uwp)_gnu_base`
petrochenkov Apr 11, 2020
9c9db3a
rustc_target: Remove some useless imports
petrochenkov Apr 11, 2020
fd0e298
rustc_target: Inherit `windows_uwp_msvc_base` from `windows_msvc_base`
petrochenkov Apr 11, 2020
88c4802
rustc_target: Inherit `windows_uwp_gnu_base` from `windows_gnu_base`
petrochenkov Apr 11, 2020
57870ea
rustc_target: Introduce `msvc_base`
petrochenkov Apr 11, 2020
8392e47
Address review comments
petrochenkov Apr 12, 2020
f2d4c93
fmt
RalfJung Apr 13, 2020
db83fdc
unit rvalue: use constant `()` instead of tuple
lcnr Apr 9, 2020
4714e20
bless mir opt tests
lcnr Apr 9, 2020
647f810
update 32 bit mir-opt tests
lcnr Apr 14, 2020
b9161ab
Do not use `DUMMY_HIR_ID` as placeholder value in node_id_to_hir_id t…
marmeladema Apr 13, 2020
c15e13a
Remove `DUMMY_HIR_ID`
marmeladema Apr 13, 2020
02e1a74
Rollup merge of #69903 - estebank:icemation, r=oli-obk
Centril Apr 15, 2020
4f84ad2
Rollup merge of #70891 - lcnr:replace-rvalue_aggregate, r=eddyb
Centril Apr 15, 2020
7276fd0
Rollup merge of #71030 - petrochenkov:linkorder2, r=nagisa
Centril Apr 15, 2020
6431325
Rollup merge of #71100 - RalfJung:miri-frame-hook, r=oli-obk
Centril Apr 15, 2020
447f4d4
Rollup merge of #71116 - marmeladema:dummy-hir-id-removal, r=eddyb
Centril Apr 15, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
6 changes: 5 additions & 1 deletion src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2399,7 +2399,11 @@ impl<'tcx> AdtDef {
None
}
Err(ErrorHandled::TooGeneric) => {
span_bug!(tcx.def_span(expr_did), "enum discriminant depends on generic arguments",)
tcx.sess.delay_span_bug(
tcx.def_span(expr_did),
"enum discriminant depends on generic arguments",
);
None
}
}
}
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
Loading