Skip to content

Commit c625d2c

Browse files
committed
propagate param def id during typeck
1 parent 7186628 commit c625d2c

File tree

65 files changed

+657
-355
lines changed

Some content is hidden

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

65 files changed

+657
-355
lines changed

src/librustc_codegen_llvm/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ fn generator_layout_and_saved_local_names(
12951295
tcx: TyCtxt<'tcx>,
12961296
def_id: DefId,
12971297
) -> (&'tcx GeneratorLayout<'tcx>, IndexVec<mir::GeneratorSavedLocal, Option<Symbol>>) {
1298-
let body = tcx.optimized_mir(def_id);
1298+
let body = tcx.optimized_mir(tcx.with_opt_param(def_id));
12991299
let generator_layout = body.generator_layout.as_ref().unwrap();
13001300
let mut generator_saved_local_names = IndexVec::from_elem(None, &generator_layout.field_tys);
13011301

src/librustc_codegen_ssa/back/symbol_export.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ fn exported_symbols_provider_local(
249249
}
250250

251251
match *mono_item {
252-
MonoItem::Fn(Instance { def: InstanceDef::Item(def_id), substs }) => {
252+
MonoItem::Fn(Instance { def: InstanceDef::Item(def_id, _), substs }) => {
253253
if substs.non_erasable_generics().next().is_some() {
254254
let symbol = ExportedSymbol::Generic(def_id, substs);
255255
symbols.push((symbol, SymbolExportLevel::Rust));

src/librustc_codegen_ssa/mir/constant.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
2525
constant: &mir::Constant<'tcx>,
2626
) -> Result<ConstValue<'tcx>, ErrorHandled> {
2727
match self.monomorphize(&constant.literal).val {
28-
ty::ConstKind::Unevaluated(def_id, substs, promoted) => self
28+
ty::ConstKind::Unevaluated(def, substs, promoted) => self
2929
.cx
3030
.tcx()
31-
.const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None)
31+
.const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None)
3232
.map_err(|err| {
3333
if promoted.is_none() {
3434
self.cx

src/librustc_infer/infer/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15381538
pub fn const_eval_resolve(
15391539
&self,
15401540
param_env: ty::ParamEnv<'tcx>,
1541-
def_id: DefId,
1541+
def: ty::WithOptParam<DefId>,
15421542
substs: SubstsRef<'tcx>,
15431543
promoted: Option<mir::Promoted>,
15441544
span: Option<Span>,
@@ -1549,7 +1549,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15491549
let (param_env, substs) = canonical.value;
15501550
// The return value is the evaluated value which doesn't contain any reference to inference
15511551
// variables, thus we don't need to substitute back the original values.
1552-
self.tcx.const_eval_resolve(param_env, def_id, substs, promoted, span)
1552+
self.tcx.const_eval_resolve(param_env, def, substs, promoted, span)
15531553
}
15541554

15551555
/// If `typ` is a type variable of some kind, resolve it one level

src/librustc_infer/traits/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ pub fn anonymize_predicate<'tcx>(
4040
ty::PredicateKind::Subtype(tcx.anonymize_late_bound_regions(data))
4141
}
4242

43-
&ty::PredicateKind::ConstEvaluatable(def_id, substs) => {
44-
ty::PredicateKind::ConstEvaluatable(def_id, substs)
43+
&ty::PredicateKind::ConstEvaluatable(def, substs) => {
44+
ty::PredicateKind::ConstEvaluatable(def, substs)
4545
}
4646

4747
ty::PredicateKind::ConstEquate(c1, c2) => ty::PredicateKind::ConstEquate(c1, c2),

src/librustc_interface/passes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -848,15 +848,15 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> {
848848
});
849849

850850
sess.time("MIR_borrow_checking", || {
851-
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(def_id));
851+
tcx.par_body_owners(|def_id| tcx.ensure().mir_borrowck(tcx.with_opt_param(def_id)));
852852
});
853853

854854
sess.time("MIR_effect_checking", || {
855855
for def_id in tcx.body_owners() {
856856
mir::transform::check_unsafety::check_unsafety(tcx, def_id);
857857

858858
if tcx.hir().body_const_context(def_id).is_some() {
859-
tcx.ensure().mir_drops_elaborated_and_const_checked(def_id);
859+
tcx.ensure().mir_drops_elaborated_and_const_checked(tcx.with_opt_param(def_id));
860860
}
861861
}
862862
});

src/librustc_metadata/rmeta/decoder/cstore_impl.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ impl IntoArgs for DefId {
7575
}
7676
}
7777

78+
impl IntoArgs for ty::WithOptParam<DefId> {
79+
fn into_args(self) -> (DefId, DefId) {
80+
(self.did, self.param_did.unwrap_or(self.did))
81+
}
82+
}
83+
7884
impl IntoArgs for CrateNum {
7985
fn into_args(self) -> (DefId, DefId) {
8086
(self.as_def_id(), self.as_def_id())

src/librustc_metadata/rmeta/encoder.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,8 @@ impl EncodeContext<'tcx> {
939939
record!(self.tables.kind[def_id] <- match impl_item.kind {
940940
ty::AssocKind::Const => {
941941
if let hir::ImplItemKind::Const(_, body_id) = ast_item.kind {
942-
let qualifs = self.tcx.at(ast_item.span).mir_const_qualif(def_id);
942+
let tcx = self.tcx.at(ast_item.span);
943+
let qualifs = tcx.mir_const_qualif(tcx.with_opt_param(def_id));
943944

944945
EntryKind::AssocConst(
945946
container,
@@ -1021,14 +1022,18 @@ impl EncodeContext<'tcx> {
10211022
fn encode_optimized_mir(&mut self, def_id: LocalDefId) {
10221023
debug!("EntryBuilder::encode_mir({:?})", def_id);
10231024
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
1024-
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(def_id));
1025+
record!(self.tables.mir[def_id.to_def_id()] <- self.tcx.optimized_mir(
1026+
self.tcx.with_opt_param(def_id.to_def_id())
1027+
));
10251028
}
10261029
}
10271030

10281031
fn encode_promoted_mir(&mut self, def_id: LocalDefId) {
10291032
debug!("EncodeContext::encode_promoted_mir({:?})", def_id);
10301033
if self.tcx.mir_keys(LOCAL_CRATE).contains(&def_id) {
1031-
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(def_id));
1034+
record!(self.tables.promoted_mir[def_id.to_def_id()] <- self.tcx.promoted_mir(
1035+
self.tcx.with_opt_param(def_id.to_def_id())
1036+
));
10321037
}
10331038
}
10341039

@@ -1086,7 +1091,8 @@ impl EncodeContext<'tcx> {
10861091
hir::ItemKind::Static(_, hir::Mutability::Mut, _) => EntryKind::MutStatic,
10871092
hir::ItemKind::Static(_, hir::Mutability::Not, _) => EntryKind::ImmStatic,
10881093
hir::ItemKind::Const(_, body_id) => {
1089-
let qualifs = self.tcx.at(item.span).mir_const_qualif(def_id);
1094+
let tcx = self.tcx.at(item.span);
1095+
let qualifs = tcx.mir_const_qualif(tcx.with_opt_param(def_id));
10901096
EntryKind::Const(
10911097
qualifs,
10921098
self.encode_rendered_const_for_body(body_id)
@@ -1328,7 +1334,7 @@ impl EncodeContext<'tcx> {
13281334
// NOTE(eddyb) `tcx.type_of(def_id)` isn't used because it's fully generic,
13291335
// including on the signature, which is inferred in `typeck_tables_of.
13301336
let hir_id = self.tcx.hir().as_local_hir_id(def_id);
1331-
let ty = self.tcx.typeck_tables_of(def_id).node_type(hir_id);
1337+
let ty = self.tcx.typeck_tables_of(self.tcx.with_opt_param(def_id)).node_type(hir_id);
13321338

13331339
record!(self.tables.kind[def_id.to_def_id()] <- match ty.kind {
13341340
ty::Generator(..) => {
@@ -1357,7 +1363,7 @@ impl EncodeContext<'tcx> {
13571363
let id = self.tcx.hir().as_local_hir_id(def_id);
13581364
let body_id = self.tcx.hir().body_owned_by(id);
13591365
let const_data = self.encode_rendered_const_for_body(body_id);
1360-
let qualifs = self.tcx.mir_const_qualif(def_id);
1366+
let qualifs = self.tcx.mir_const_qualif(self.tcx.with_opt_param(def_id.to_def_id()));
13611367

13621368
record!(self.tables.kind[def_id.to_def_id()] <- EntryKind::AnonConst(qualifs, const_data));
13631369
record!(self.tables.visibility[def_id.to_def_id()] <- ty::Visibility::Public);
@@ -1744,8 +1750,9 @@ struct PrefetchVisitor<'tcx> {
17441750
impl<'tcx> PrefetchVisitor<'tcx> {
17451751
fn prefetch_mir(&self, def_id: LocalDefId) {
17461752
if self.mir_keys.contains(&def_id) {
1747-
self.tcx.ensure().optimized_mir(def_id);
1748-
self.tcx.ensure().promoted_mir(def_id);
1753+
let def = self.tcx.with_opt_param(def_id).to_global();
1754+
self.tcx.ensure().optimized_mir(def);
1755+
self.tcx.ensure().promoted_mir(def);
17491756
}
17501757
}
17511758
}

src/librustc_middle/dep_graph/dep_node.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,43 @@ impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for CrateNum {
361361
}
362362
}
363363

364+
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for ty::WithOptParam<DefId> {
365+
#[inline]
366+
fn can_reconstruct_query_key() -> bool {
367+
true
368+
}
369+
370+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
371+
tcx.def_path_hash(self.did).0
372+
}
373+
374+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
375+
tcx.def_path_str(self.did)
376+
}
377+
378+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
379+
dep_node.extract_def_id(tcx).map(|def_id| tcx.with_opt_param(def_id))
380+
}
381+
}
382+
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for ty::WithOptParam<LocalDefId> {
383+
#[inline]
384+
fn can_reconstruct_query_key() -> bool {
385+
true
386+
}
387+
388+
fn to_fingerprint(&self, tcx: TyCtxt<'tcx>) -> Fingerprint {
389+
tcx.def_path_hash(self.did.to_def_id()).0
390+
}
391+
392+
fn to_debug_str(&self, tcx: TyCtxt<'tcx>) -> String {
393+
tcx.def_path_str(self.did.to_def_id())
394+
}
395+
396+
fn recover(tcx: TyCtxt<'tcx>, dep_node: &DepNode) -> Option<Self> {
397+
dep_node.extract_def_id(tcx).map(|def_id| tcx.with_opt_param(def_id.expect_local()))
398+
}
399+
}
400+
364401
impl<'tcx> DepNodeParams<TyCtxt<'tcx>> for (DefId, DefId) {
365402
#[inline]
366403
fn can_reconstruct_query_key() -> bool {

src/librustc_middle/mir/interpret/queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ impl<'tcx> TyCtxt<'tcx> {
3434
pub fn const_eval_resolve(
3535
self,
3636
param_env: ty::ParamEnv<'tcx>,
37-
def_id: DefId,
37+
def: ty::WithOptParam<DefId>,
3838
substs: SubstsRef<'tcx>,
3939
promoted: Option<mir::Promoted>,
4040
span: Option<Span>,
4141
) -> ConstEvalResult<'tcx> {
42-
match ty::Instance::resolve(self, param_env, def_id, substs) {
42+
match ty::Instance::resolve_const_arg(self, param_env, def, substs) {
4343
Ok(Some(instance)) => {
4444
let cid = GlobalId { instance, promoted };
4545
self.const_eval_global_id(param_env, cid, span)

0 commit comments

Comments
 (0)