Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ provide! { tcx, def_id, other, cdata,
inferred_outlives_of => { table_defaulted_array }
explicit_super_predicates_of => { table_defaulted_array }
explicit_implied_predicates_of => { table_defaulted_array }
param_env => { table }
type_of => { table }
type_alias_is_lazy => { table_direct }
variances_of => { table }
Expand Down
19 changes: 19 additions & 0 deletions compiler/rustc_metadata/src/rmeta/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}
}
if should_encode_param_env(def_kind) {
record!(self.tables.param_env[def_id] <- tcx.param_env(def_id));
}
if tcx.is_conditionally_const(def_id) {
record!(self.tables.const_conditions[def_id] <- self.tcx.const_conditions(def_id));
}
Expand Down Expand Up @@ -2214,6 +2217,22 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
}
}

fn should_encode_param_env(def_kind: DefKind) -> bool {
matches!(
def_kind,
DefKind::Impl { of_trait: _ }
| DefKind::Struct
| DefKind::Enum
| DefKind::Union
| DefKind::AnonConst
| DefKind::AssocFn
| DefKind::AssocConst
| DefKind::AssocTy
| DefKind::Fn
| DefKind::Closure
)
}

/// Used to prefetch queries which will be needed later by metadata encoding.
/// Only a subset of the queries are actually prefetched to keep this code smaller.
fn prefetch_mir(tcx: TyCtxt<'_>) {
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 @@ -428,6 +428,7 @@ define_tables! {
lookup_deprecation_entry: Table<DefIndex, LazyValue<attrs::Deprecation>>,
explicit_predicates_of: Table<DefIndex, LazyValue<ty::GenericPredicates<'static>>>,
generics_of: Table<DefIndex, LazyValue<ty::Generics>>,
param_env: Table<DefIndex, LazyValue<ty::ParamEnv<'static>>>,
type_of: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, Ty<'static>>>>,
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<'static, ty::PolyFnSig<'static>>>>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,6 +1569,7 @@ rustc_queries! {
query param_env(def_id: DefId) -> ty::ParamEnv<'tcx> {
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
feedable
separate_provide_extern
}

/// Like `param_env`, but returns the `ParamEnv` after all opaque types have been
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 @@ -148,4 +148,5 @@ parameterized_over_tcx! {
ty::Clause,
ty::ClauseKind,
ty::ImplTraitHeader,
ty::ParamEnv,
}
11 changes: 4 additions & 7 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc_middle::ty::{
fold_regions,
};
use rustc_span::DUMMY_SP;
use rustc_span::def_id::{CRATE_DEF_ID, DefId, LocalDefId};
use rustc_span::def_id::{DefId, LocalDefId};
use rustc_trait_selection::traits;
use tracing::instrument;

Expand Down Expand Up @@ -119,7 +119,7 @@ fn adt_sized_constraint<'tcx>(
}

/// See `ParamEnv` struct definition for details.
fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
fn param_env(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::ParamEnv<'_> {
// Compute the bounds on Self and the type parameters.
let ty::InstantiatedPredicates { mut predicates, .. } =
tcx.predicates_of(def_id).instantiate_identity(tcx);
Expand All @@ -145,7 +145,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
// We accounted for the binder of the fn sig, so skip the binder.
sig.skip_binder().visit_with(&mut ImplTraitInTraitFinder {
tcx,
fn_def_id: def_id,
fn_def_id: def_id.to_def_id(),
bound_vars: sig.bound_vars(),
predicates: &mut predicates,
seen: FxHashSet::default(),
Expand All @@ -163,12 +163,9 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
);
}

let local_did = def_id.as_local();

let unnormalized_env = ty::ParamEnv::new(tcx.mk_clauses(&predicates));

let body_id = local_did.unwrap_or(CRATE_DEF_ID);
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
let cause = traits::ObligationCause::misc(tcx.def_span(def_id), def_id);
traits::normalize_param_env_or_error(tcx, unnormalized_env, cause)
}

Expand Down
Loading