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

refactor(exporter): always use State::param_env #685

Merged
merged 1 commit into from
May 22, 2024
Merged
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
8 changes: 4 additions & 4 deletions frontend/exporter/src/constant_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {

// Solve the trait obligations
let parent_def_id = tcx.parent(ucv.def);
let param_env = tcx.param_env(s.owner_id());
let param_env = s.param_env();
let trait_refs =
solve_item_traits(s, param_env, parent_def_id, ucv.substs, None);

Expand Down Expand Up @@ -391,13 +391,13 @@ pub trait ConstantExt<'tcx>: Sized + std::fmt::Debug {
}
impl<'tcx> ConstantExt<'tcx> for rustc_middle::ty::Const<'tcx> {
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> {
let evaluated = self.eval(s.base().tcx, get_param_env(s));
let evaluated = self.eval(s.base().tcx, s.param_env());
(&evaluated != self).then_some(evaluated)
}
}
impl<'tcx> ConstantExt<'tcx> for rustc_middle::mir::ConstantKind<'tcx> {
fn eval_constant<S: UnderOwnerState<'tcx>>(&self, s: &S) -> Option<Self> {
let evaluated = self.eval(s.base().tcx, get_param_env(s));
let evaluated = self.eval(s.base().tcx, s.param_env());
(&evaluated != self).then_some(evaluated)
}
}
Expand Down Expand Up @@ -505,7 +505,7 @@ pub(crate) fn const_value_reference_to_constant_expr<'tcx, S: UnderOwnerState<'t
let tcx = s.base().tcx;

// We use [try_destructure_mir_constant] to destructure the constant
let param_env = get_param_env(s);
let param_env = s.param_env();
// We have to clone some values: it is a bit annoying, but I don't
// manage to get the lifetimes working otherwise...
let cvalue = rustc_middle::mir::ConstantKind::Val(val, ty);
Expand Down
11 changes: 8 additions & 3 deletions frontend/exporter/src/rustc_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,14 @@ pub fn translate_span(span: rustc_span::Span, sess: &rustc_session::Session) ->
}
}

#[tracing::instrument(skip(s))]
pub(crate) fn get_param_env<'tcx, S: UnderOwnerState<'tcx>>(s: &S) -> ty::ParamEnv<'tcx> {
s.base().tcx.param_env(s.owner_id())
pub trait ParamEnv<'tcx> {
fn param_env(&self) -> ty::ParamEnv<'tcx>;
}

impl<'tcx, S: UnderOwnerState<'tcx>> ParamEnv<'tcx> for S {
fn param_env(&self) -> ty::ParamEnv<'tcx> {
self.base().tcx.param_env(self.owner_id())
}
}

#[tracing::instrument]
Expand Down
2 changes: 1 addition & 1 deletion frontend/exporter/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ pub fn super_clause_to_clause_and_impl_expr<'tcx, S: UnderOwnerState<'tcx>>(
let impl_expr = new_clause
.as_predicate()
.to_opt_poly_trait_pred()?
.impl_expr(s, get_param_env(s));
.impl_expr(s, s.param_env());
let mut new_clause_no_binder = new_clause.sinto(s);
new_clause_no_binder.id = original_predicate_id;
Some((new_clause_no_binder, impl_expr, span.sinto(s)))
Expand Down
15 changes: 7 additions & 8 deletions frontend/exporter/src/types/copied.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1605,12 +1605,12 @@ impl Alias {
let rebased_substs = alias_ty.rebase_substs_onto_impl(alias_ty.substs, tcx);
let norm_rebased_substs = tcx.try_subst_and_normalize_erasing_regions(
rebased_substs,
get_param_env(s),
s.param_env(),
EarlyBinder::bind(trait_ref),
);
let norm_substs = tcx.try_subst_and_normalize_erasing_regions(
alias_ty.substs,
get_param_env(s),
s.param_env(),
EarlyBinder::bind(trait_ref),
);
let early_binder_substs =
Expand All @@ -1636,7 +1636,7 @@ impl Alias {
};
AliasKind::Projection {
assoc_item: tcx.associated_item(alias_ty.def_id).sinto(s),
impl_expr: poly_trait_ref.impl_expr(s, get_param_env(s)),
impl_expr: poly_trait_ref.impl_expr(s, s.param_env()),
}
}
RustAliasKind::Inherent => AliasKind::Inherent,
Expand Down Expand Up @@ -1683,8 +1683,7 @@ pub enum Ty {
rustc_middle::ty::TyKind::Adt(adt_def, substs) => {
let def_id = adt_def.did().sinto(state);
let generic_args: Vec<GenericArg> = substs.sinto(state);
let param_env = state.base().tcx.param_env(state.owner_id());
let trait_refs = solve_item_traits(state, param_env, adt_def.did(), substs, None);
let trait_refs = solve_item_traits(state, state.param_env(), adt_def.did(), substs, None);
Ty::Adt { def_id, generic_args, trait_refs }
},
)]
Expand Down Expand Up @@ -2224,9 +2223,9 @@ pub enum ExprKind {
let tcx = gstate.base().tcx;
r#impl = tcx.opt_associated_item(*def_id).as_ref().and_then(|assoc| {
poly_trait_ref(gstate, assoc, substs)
}).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, get_param_env(gstate)));
}).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, gstate.param_env()));
generic_args = substs.sinto(gstate);
bounds_impls = solve_item_traits(gstate, get_param_env(gstate), *def_id, substs, None);
bounds_impls = solve_item_traits(gstate, gstate.param_env(), *def_id, substs, None);
Expr {
contents,
span: e.span.sinto(gstate),
Expand Down Expand Up @@ -2478,7 +2477,7 @@ pub enum ExprKind {
let tcx = gstate.base().tcx;
tcx.opt_associated_item(*def_id).as_ref().and_then(|assoc| {
poly_trait_ref(gstate, assoc, substs)
}).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, tcx.param_env(gstate.owner_id())))
}).map(|poly_trait_ref| poly_trait_ref.impl_expr(gstate, gstate.param_env()))
})]
r#impl: Option<ImplExpr>,
},
Expand Down
6 changes: 3 additions & 3 deletions frontend/exporter/src/types/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ pub(crate) fn get_function_from_def_id_and_substs<'tcx, S: BaseState<'tcx> + Has
substs: rustc_middle::ty::subst::SubstsRef<'tcx>,
) -> (DefId, Vec<GenericArg>, Vec<ImplExpr>, Option<ImplExpr>) {
let tcx = s.base().tcx;
let param_env = tcx.param_env(s.owner_id());
let param_env = s.param_env();

// Retrieve the trait requirements for the **method**.
// For instance, if we write:
Expand Down Expand Up @@ -852,7 +852,7 @@ pub enum AggregateKind {
Tuple,
#[custom_arm(rustc_middle::mir::AggregateKind::Adt(def_id, vid, substs, annot, fid) => {
let adt_kind = s.base().tcx.adt_def(def_id).adt_kind().sinto(s);
let param_env = s.base().tcx.param_env(s.owner_id());
let param_env = s.param_env();
let trait_refs = solve_item_traits(s, param_env, *def_id, substs, None);
AggregateKind::Adt(
def_id.sinto(s),
Expand Down Expand Up @@ -884,7 +884,7 @@ pub enum AggregateKind {

// Solve the trait obligations. Note that we solve the parent
let tcx = s.base().tcx;
let param_env = tcx.param_env(s.owner_id());
let param_env = s.param_env();
let parent_substs = closure.parent_substs();
let substs = tcx.mk_substs(parent_substs);
// Retrieve the predicates from the parent (i.e., the function which calls
Expand Down
2 changes: 1 addition & 1 deletion frontend/exporter/src/types/mir_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub fn get_trait_info<'tcx, S: UnderOwnerState<'tcx>>(
assoc: &rustc_middle::ty::AssocItem,
) -> ImplExpr {
let tcx = s.base().tcx;
let param_env = tcx.param_env(s.owner_id());
let param_env = s.param_env();

// Retrieve the trait
let tr_def_id = tcx.trait_of_item(assoc.def_id).unwrap();
Expand Down
Loading