Skip to content

Commit df768c5

Browse files
committed
Auto merge of rust-lang#71162 - Centril:rollup-jzg6ykc, r=Centril
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
2 parents 351eefe + 7341cad commit df768c5

File tree

151 files changed

+1255
-563
lines changed

Some content is hidden

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

151 files changed

+1255
-563
lines changed

src/librustc_ast_lowering/lib.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ struct LoweringContext<'a, 'hir: 'a> {
168168

169169
current_hir_id_owner: Vec<(LocalDefId, u32)>,
170170
item_local_id_counters: NodeMap<u32>,
171-
node_id_to_hir_id: IndexVec<NodeId, hir::HirId>,
171+
node_id_to_hir_id: IndexVec<NodeId, Option<hir::HirId>>,
172172

173173
allow_try_trait: Option<Lrc<[Symbol]>>,
174174
allow_gen_future: Option<Lrc<[Symbol]>>,
@@ -522,15 +522,16 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
522522
}
523523

524524
self.lower_node_id(CRATE_NODE_ID);
525-
debug_assert!(self.node_id_to_hir_id[CRATE_NODE_ID] == hir::CRATE_HIR_ID);
525+
debug_assert!(self.node_id_to_hir_id[CRATE_NODE_ID] == Some(hir::CRATE_HIR_ID));
526526

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

530530
let module = self.lower_mod(&c.module);
531531
let attrs = self.lower_attrs(&c.attrs);
532532
let body_ids = body_ids(&self.bodies);
533-
let proc_macros = c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id]).collect();
533+
let proc_macros =
534+
c.proc_macros.iter().map(|id| self.node_id_to_hir_id[*id].unwrap()).collect();
534535

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

@@ -571,26 +572,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
571572
ast_node_id: NodeId,
572573
alloc_hir_id: impl FnOnce(&mut Self) -> hir::HirId,
573574
) -> hir::HirId {
574-
if ast_node_id == DUMMY_NODE_ID {
575-
return hir::DUMMY_HIR_ID;
576-
}
575+
assert_ne!(ast_node_id, DUMMY_NODE_ID);
577576

578577
let min_size = ast_node_id.as_usize() + 1;
579578

580579
if min_size > self.node_id_to_hir_id.len() {
581-
self.node_id_to_hir_id.resize(min_size, hir::DUMMY_HIR_ID);
580+
self.node_id_to_hir_id.resize(min_size, None);
582581
}
583582

584-
let existing_hir_id = self.node_id_to_hir_id[ast_node_id];
585-
586-
if existing_hir_id == hir::DUMMY_HIR_ID {
583+
if let Some(existing_hir_id) = self.node_id_to_hir_id[ast_node_id] {
584+
existing_hir_id
585+
} else {
587586
// Generate a new `HirId`.
588587
let hir_id = alloc_hir_id(self);
589-
self.node_id_to_hir_id[ast_node_id] = hir_id;
588+
self.node_id_to_hir_id[ast_node_id] = Some(hir_id);
590589

591590
hir_id
592-
} else {
593-
existing_hir_id
594591
}
595592
}
596593

src/librustc_codegen_ssa/back/link.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_session::search_paths::PathKind;
1212
/// need out of the shared crate context before we get rid of it.
1313
use rustc_session::{filesearch, Session};
1414
use rustc_span::symbol::Symbol;
15-
use rustc_target::spec::{LinkerFlavor, PanicStrategy, RelroLevel};
15+
use rustc_target::spec::{LinkerFlavor, LldFlavor, PanicStrategy, RelroLevel};
1616

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

15321534
// OBJECT-FILES-NO, AUDIT-ORDER
1533-
// We want to, by default, prevent the compiler from accidentally leaking in
1534-
// any system libraries, so we may explicitly ask linkers to not link to any
1535-
// libraries by default. Note that this does not happen for windows because
1536-
// windows pulls in some large number of libraries and I couldn't quite
1537-
// figure out which subset we wanted.
1538-
//
1539-
// This is all naturally configurable via the standard methods as well.
1535+
// We want to prevent the compiler from accidentally leaking in any system libraries,
1536+
// so by default we tell linkers not to link to any default libraries.
15401537
if !sess.opts.cg.default_linker_libraries.unwrap_or(false)
15411538
&& sess.target.target.options.no_default_libraries
15421539
{

src/librustc_codegen_ssa/back/linker.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -631,15 +631,7 @@ impl<'a> Linker for MsvcLinker<'a> {
631631
}
632632

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

645637
fn include_path(&mut self, path: &Path) {

src/librustc_hir/definitions.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
pub use crate::def_id::DefPathHash;
88
use crate::def_id::{CrateNum, DefId, DefIndex, LocalDefId, CRATE_DEF_INDEX, LOCAL_CRATE};
99
use crate::hir;
10-
use crate::hir_id::DUMMY_HIR_ID;
1110

1211
use rustc_ast::ast;
1312
use rustc_ast::crate_disambiguator::CrateDisambiguator;
@@ -87,7 +86,7 @@ pub struct Definitions {
8786
node_id_to_def_id: FxHashMap<ast::NodeId, LocalDefId>,
8887
def_id_to_node_id: IndexVec<LocalDefId, ast::NodeId>,
8988

90-
pub(super) node_id_to_hir_id: IndexVec<ast::NodeId, hir::HirId>,
89+
pub(super) node_id_to_hir_id: IndexVec<ast::NodeId, Option<hir::HirId>>,
9190
/// The reverse mapping of `node_id_to_hir_id`.
9291
pub(super) hir_id_to_node_id: FxHashMap<hir::HirId, ast::NodeId>,
9392

@@ -345,8 +344,7 @@ impl Definitions {
345344
#[inline]
346345
pub fn as_local_hir_id(&self, def_id: DefId) -> Option<hir::HirId> {
347346
if let Some(def_id) = def_id.as_local() {
348-
let hir_id = self.local_def_id_to_hir_id(def_id);
349-
if hir_id != DUMMY_HIR_ID { Some(hir_id) } else { None }
347+
Some(self.local_def_id_to_hir_id(def_id))
350348
} else {
351349
None
352350
}
@@ -359,11 +357,22 @@ impl Definitions {
359357

360358
#[inline]
361359
pub fn node_id_to_hir_id(&self, node_id: ast::NodeId) -> hir::HirId {
360+
self.node_id_to_hir_id[node_id].unwrap()
361+
}
362+
363+
#[inline]
364+
pub fn opt_node_id_to_hir_id(&self, node_id: ast::NodeId) -> Option<hir::HirId> {
362365
self.node_id_to_hir_id[node_id]
363366
}
364367

365368
#[inline]
366369
pub fn local_def_id_to_hir_id(&self, id: LocalDefId) -> hir::HirId {
370+
let node_id = self.def_id_to_node_id[id];
371+
self.node_id_to_hir_id[node_id].unwrap()
372+
}
373+
374+
#[inline]
375+
pub fn opt_local_def_id_to_hir_id(&self, id: LocalDefId) -> Option<hir::HirId> {
367376
let node_id = self.def_id_to_node_id[id];
368377
self.node_id_to_hir_id[node_id]
369378
}
@@ -470,7 +479,10 @@ impl Definitions {
470479

471480
/// Initializes the `ast::NodeId` to `HirId` mapping once it has been generated during
472481
/// AST to HIR lowering.
473-
pub fn init_node_id_to_hir_id_mapping(&mut self, mapping: IndexVec<ast::NodeId, hir::HirId>) {
482+
pub fn init_node_id_to_hir_id_mapping(
483+
&mut self,
484+
mapping: IndexVec<ast::NodeId, Option<hir::HirId>>,
485+
) {
474486
assert!(
475487
self.node_id_to_hir_id.is_empty(),
476488
"trying to initialize `NodeId` -> `HirId` mapping twice"
@@ -481,7 +493,7 @@ impl Definitions {
481493
self.hir_id_to_node_id = self
482494
.node_id_to_hir_id
483495
.iter_enumerated()
484-
.map(|(node_id, &hir_id)| (hir_id, node_id))
496+
.filter_map(|(node_id, &hir_id)| hir_id.map(|hir_id| (hir_id, node_id)))
485497
.collect();
486498
}
487499

src/librustc_hir/hir_id.rs

-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,4 @@ pub const CRATE_HIR_ID: HirId = HirId {
4545
local_id: ItemLocalId::from_u32(0),
4646
};
4747

48-
pub const DUMMY_HIR_ID: HirId =
49-
HirId { owner: LocalDefId { local_def_index: CRATE_DEF_INDEX }, local_id: DUMMY_ITEM_LOCAL_ID };
50-
5148
pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX;

src/librustc_middle/hir/map/collector.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -250,23 +250,16 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
250250
None => format!("{:?}", node),
251251
};
252252

253-
let forgot_str = if hir_id == hir::DUMMY_HIR_ID {
254-
format!("\nMaybe you forgot to lower the node id {:?}?", node_id)
255-
} else {
256-
String::new()
257-
};
258-
259253
span_bug!(
260254
span,
261255
"inconsistent DepNode at `{:?}` for `{}`: \
262-
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?}){}",
256+
current_dep_node_owner={} ({:?}), hir_id.owner={} ({:?})",
263257
self.source_map.span_to_string(span),
264258
node_str,
265259
self.definitions.def_path(self.current_dep_node_owner).to_string_no_crate(),
266260
self.current_dep_node_owner,
267261
self.definitions.def_path(hir_id.owner).to_string_no_crate(),
268262
hir_id.owner,
269-
forgot_str,
270263
)
271264
}
272265
}

src/librustc_middle/hir/map/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,21 @@ impl<'hir> Map<'hir> {
214214
self.tcx.definitions.node_id_to_hir_id(node_id)
215215
}
216216

217+
#[inline]
218+
pub fn opt_node_id_to_hir_id(&self, node_id: NodeId) -> Option<HirId> {
219+
self.tcx.definitions.opt_node_id_to_hir_id(node_id)
220+
}
221+
217222
#[inline]
218223
pub fn local_def_id_to_hir_id(&self, def_id: LocalDefId) -> HirId {
219224
self.tcx.definitions.local_def_id_to_hir_id(def_id)
220225
}
221226

227+
#[inline]
228+
pub fn opt_local_def_id_to_hir_id(&self, def_id: LocalDefId) -> Option<HirId> {
229+
self.tcx.definitions.opt_local_def_id_to_hir_id(def_id)
230+
}
231+
222232
pub fn def_kind(&self, hir_id: HirId) -> Option<DefKind> {
223233
let node = self.find(hir_id)?;
224234

src/librustc_middle/middle/stability.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,6 @@ fn late_report_deprecation(
215215
suggestion: Option<Symbol>,
216216
lint: &'static Lint,
217217
span: Span,
218-
def_id: DefId,
219218
hir_id: HirId,
220219
) {
221220
if span.in_derive_expansion() {
@@ -229,9 +228,6 @@ fn late_report_deprecation(
229228
}
230229
diag.emit()
231230
});
232-
if hir_id == hir::DUMMY_HIR_ID {
233-
span_bug!(span, "emitted a {} lint with dummy HIR id: {:?}", lint.name, def_id);
234-
}
235231
}
236232

237233
/// Result of `TyCtxt::eval_stability`.
@@ -296,7 +292,7 @@ impl<'tcx> TyCtxt<'tcx> {
296292
if !skip {
297293
let (message, lint) =
298294
deprecation_message(&depr_entry.attr, &self.def_path_str(def_id));
299-
late_report_deprecation(self, &message, None, lint, span, def_id, id);
295+
late_report_deprecation(self, &message, None, lint, span, id);
300296
}
301297
};
302298
}
@@ -319,15 +315,7 @@ impl<'tcx> TyCtxt<'tcx> {
319315
if let Some(depr) = &stability.rustc_depr {
320316
let (message, lint) =
321317
rustc_deprecation_message(depr, &self.def_path_str(def_id));
322-
late_report_deprecation(
323-
self,
324-
&message,
325-
depr.suggestion,
326-
lint,
327-
span,
328-
def_id,
329-
id,
330-
);
318+
late_report_deprecation(self, &message, depr.suggestion, lint, span, id);
331319
}
332320
}
333321
}

src/librustc_middle/ty/context.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -1126,13 +1126,16 @@ impl<'tcx> TyCtxt<'tcx> {
11261126

11271127
let mut trait_map: FxHashMap<_, FxHashMap<_, _>> = FxHashMap::default();
11281128
for (k, v) in resolutions.trait_map {
1129-
let hir_id = definitions.node_id_to_hir_id(k);
1130-
let map = trait_map.entry(hir_id.owner).or_default();
1131-
let v = v
1132-
.into_iter()
1133-
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
1134-
.collect();
1135-
map.insert(hir_id.local_id, StableVec::new(v));
1129+
// FIXME(#71104) Should really be using just `node_id_to_hir_id` but
1130+
// some `NodeId` do not seem to have a corresponding HirId.
1131+
if let Some(hir_id) = definitions.opt_node_id_to_hir_id(k) {
1132+
let map = trait_map.entry(hir_id.owner).or_default();
1133+
let v = v
1134+
.into_iter()
1135+
.map(|tc| tc.map_import_ids(|id| definitions.node_id_to_hir_id(id)))
1136+
.collect();
1137+
map.insert(hir_id.local_id, StableVec::new(v));
1138+
}
11361139
}
11371140

11381141
GlobalCtxt {

src/librustc_mir/const_eval/eval_queries.rs

+22-19
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{error_to_const_error, CompileTimeEvalContext, CompileTimeInterpreter, MemoryExtra};
22
use crate::interpret::eval_nullary_intrinsic;
33
use crate::interpret::{
4-
intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, ImmTy, Immediate, InternKind,
4+
intern_const_alloc_recursive, Allocation, ConstValue, GlobalId, Immediate, InternKind,
55
InterpCx, InterpResult, MPlaceTy, MemoryKind, OpTy, RawConst, RefTracking, Scalar,
66
ScalarMaybeUndef, StackPopCleanup,
77
};
@@ -147,25 +147,28 @@ pub(super) fn op_to_const<'tcx>(
147147
match immediate {
148148
Ok(mplace) => to_const_value(mplace),
149149
// see comment on `let try_as_immediate` above
150-
Err(ImmTy { imm: Immediate::Scalar(x), .. }) => match x {
151-
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
152-
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
150+
Err(imm) => match *imm {
151+
Immediate::Scalar(x) => match x {
152+
ScalarMaybeUndef::Scalar(s) => ConstValue::Scalar(s),
153+
ScalarMaybeUndef::Undef => to_const_value(op.assert_mem_place(ecx)),
154+
},
155+
Immediate::ScalarPair(a, b) => {
156+
let (data, start) = match a.not_undef().unwrap() {
157+
Scalar::Ptr(ptr) => {
158+
(ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id), ptr.offset.bytes())
159+
}
160+
Scalar::Raw { .. } => (
161+
ecx.tcx
162+
.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"" as &[u8])),
163+
0,
164+
),
165+
};
166+
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
167+
let start = start.try_into().unwrap();
168+
let len: usize = len.try_into().unwrap();
169+
ConstValue::Slice { data, start, end: start + len }
170+
}
153171
},
154-
Err(ImmTy { imm: Immediate::ScalarPair(a, b), .. }) => {
155-
let (data, start) = match a.not_undef().unwrap() {
156-
Scalar::Ptr(ptr) => {
157-
(ecx.tcx.alloc_map.lock().unwrap_memory(ptr.alloc_id), ptr.offset.bytes())
158-
}
159-
Scalar::Raw { .. } => (
160-
ecx.tcx.intern_const_alloc(Allocation::from_byte_aligned_bytes(b"" as &[u8])),
161-
0,
162-
),
163-
};
164-
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
165-
let start = start.try_into().unwrap();
166-
let len: usize = len.try_into().unwrap();
167-
ConstValue::Slice { data, start, end: start + len }
168-
}
169172
}
170173
}
171174

src/librustc_mir/const_eval/machine.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use rustc_middle::mir::AssertMessage;
1313
use rustc_span::symbol::Symbol;
1414

1515
use crate::interpret::{
16-
self, AllocId, Allocation, GlobalId, ImmTy, InterpCx, InterpResult, Memory, MemoryKind, OpTy,
17-
PlaceTy, Pointer, Scalar,
16+
self, AllocId, Allocation, Frame, GlobalId, ImmTy, InterpCx, InterpResult, Memory, MemoryKind,
17+
OpTy, PlaceTy, Pointer, Scalar,
1818
};
1919

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

344344
#[inline(always)]
345-
fn stack_push(_ecx: &mut InterpCx<'mir, 'tcx, Self>) -> InterpResult<'tcx> {
346-
Ok(())
345+
fn init_frame_extra(
346+
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
347+
frame: Frame<'mir, 'tcx>,
348+
) -> InterpResult<'tcx, Frame<'mir, 'tcx>> {
349+
Ok(frame)
347350
}
348351

349352
fn before_access_global(

0 commit comments

Comments
 (0)