Skip to content

Commit

Permalink
Auto merge of #109089 - compiler-errors:opt_rpitit_info-follow-up, r=…
Browse files Browse the repository at this point in the history
…spastorino

Encode `opt_rpitit_info` for associated types

Follow-up, only last commit matters

r? `@spastorino`

This needs a perf run after the parent pr lands
  • Loading branch information
bors committed Mar 15, 2023
2 parents e84e5ff + 0404e26 commit 992d154
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 8 deletions.
5 changes: 3 additions & 2 deletions compiler/rustc_metadata/src/rmeta/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
_ => bug!("cannot get associated-item of `{:?}`", self.def_key(id)),
};
let container = self.root.tables.assoc_container.get(self, id).unwrap();
let opt_rpitit_info =
self.root.tables.opt_rpitit_info.get(self, id).map(|d| d.decode(self));

ty::AssocItem {
name,
Expand All @@ -1095,8 +1097,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
trait_item_def_id: self.get_trait_item_def_id(id),
container,
fn_has_self_parameter: has_self,
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): We need to encode this
opt_rpitit_info: None,
opt_rpitit_info,
}
}

Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1350,6 +1350,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
if trait_item.kind == ty::AssocKind::Fn {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
}
if let Some(rpitit_info) = trait_item.opt_rpitit_info {
let rpitit_info = self.lazy(rpitit_info);
self.tables.opt_rpitit_info.set_some(def_id.index, rpitit_info);
}
}

fn encode_info_for_impl_item(&mut self, def_id: DefId) {
Expand Down Expand Up @@ -1384,6 +1388,10 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.fn_sig[def_id] <- tcx.fn_sig(def_id));
self.tables.is_intrinsic.set(def_id.index, tcx.is_intrinsic(def_id));
}
if let Some(rpitit_info) = impl_item.opt_rpitit_info {
let rpitit_info = self.lazy(rpitit_info);
self.tables.opt_rpitit_info.set_some(def_id.index, rpitit_info);
}
}

fn encode_mir(&mut self) {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ define_tables! {
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>,
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,

- optional:
attributes: Table<DefIndex, LazyArray<ast::Attribute>>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/parameterized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ trivially_parameterized_over_tcx! {
ty::DeducedParamAttrs,
ty::Generics,
ty::ImplPolarity,
ty::ImplTraitInTraitData,
ty::ReprOptions,
ty::TraitDef,
ty::UnusedGenericParams,
Expand Down
9 changes: 3 additions & 6 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,9 @@ fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] {
fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
// When computing the param_env of an RPITIT, copy param_env of the containing function. The
// synthesized associated type doesn't have extra predicates to assume.
let def_id =
if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
fn_def_id
} else {
def_id
};
if let Some(ImplTraitInTraitData::Trait { fn_def_id, .. }) = tcx.opt_rpitit_info(def_id) {
return tcx.param_env(fn_def_id);
}

// Compute the bounds on Self and the type parameters.
let ty::InstantiatedPredicates { mut predicates, .. } =
Expand Down

0 comments on commit 992d154

Please sign in to comment.