Skip to content

Commit 62df973

Browse files
committed
Use Environment instead of ty::ParamEnv in chalk context
1 parent cbbd70d commit 62df973

File tree

11 files changed

+271
-103
lines changed

11 files changed

+271
-103
lines changed

src/librustc/dep_graph/dep_node.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
7070
use std::fmt;
7171
use std::hash::Hash;
7272
use syntax_pos::symbol::InternedString;
73+
use traits;
7374
use traits::query::{
7475
CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpEqGoal, CanonicalTypeOpSubtypeGoal,
7576
CanonicalPredicateGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpNormalizeGoal,
@@ -550,6 +551,7 @@ define_dep_nodes!( <'tcx>
550551
[anon] TraitSelect,
551552

552553
[] ParamEnv(DefId),
554+
[] Environment(DefId),
553555
[] DescribeDef(DefId),
554556

555557
// FIXME(mw): DefSpans are not really inputs since they are derived from
@@ -669,7 +671,7 @@ define_dep_nodes!( <'tcx>
669671
[input] Features,
670672

671673
[] ProgramClausesFor(DefId),
672-
[] ProgramClausesForEnv(ParamEnv<'tcx>),
674+
[] ProgramClausesForEnv(traits::Environment<'tcx>),
673675
[] WasmImportModuleMap(CrateNum),
674676
[] ForeignModules(CrateNum),
675677

src/librustc/ich/impls_ty.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,15 @@ impl_stable_hash_for!(enum traits::QuantifierKind {
14181418
Existential
14191419
});
14201420

1421+
<<<<<<< HEAD
14211422
impl_stable_hash_for!(struct ty::subst::UserSubsts<'tcx> { substs, user_self_ty });
14221423

14231424
impl_stable_hash_for!(struct ty::subst::UserSelfTy<'tcx> { impl_def_id, self_ty });
14241425

1426+
=======
1427+
impl_stable_hash_for!(
1428+
impl<'tcx> for struct traits::Environment<'tcx> {
1429+
clauses,
1430+
}
1431+
);
1432+
>>>>>>> Use `Environment` instead of `ty::ParamEnv` in chalk context

src/librustc/traits/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ pub type TraitObligations<'tcx> = Vec<TraitObligation<'tcx>>;
278278
/// * `DomainGoal`
279279
/// * `Goal`
280280
/// * `Clause`
281+
/// * `Environment`
282+
/// * `InEnvironment`
281283
/// are used for representing the trait system in the form of
282284
/// logic programming clauses. They are part of the interface
283285
/// for the chalk SLG solver.
@@ -378,6 +380,33 @@ pub struct ProgramClause<'tcx> {
378380
pub hypotheses: Goals<'tcx>,
379381
}
380382

383+
/// A set of clauses that we assume to be true.
384+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
385+
pub struct Environment<'tcx> {
386+
pub clauses: Clauses<'tcx>,
387+
}
388+
389+
impl Environment<'tcx> {
390+
pub fn with<G>(self, goal: G) -> InEnvironment<'tcx, G> {
391+
InEnvironment {
392+
environment: self,
393+
goal,
394+
}
395+
}
396+
}
397+
398+
/// Something (usually a goal), along with an environment.
399+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
400+
pub struct InEnvironment<'tcx, G> {
401+
pub environment: Environment<'tcx>,
402+
pub goal: G,
403+
}
404+
405+
/// Compute the environment of the given item.
406+
fn environment<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>, _def_id: DefId) -> Environment<'tcx> {
407+
panic!()
408+
}
409+
381410
pub type Selection<'tcx> = Vtable<'tcx, PredicateObligation<'tcx>>;
382411

383412
#[derive(Clone,Debug)]
@@ -1080,6 +1109,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
10801109
codegen_fulfill_obligation: codegen::codegen_fulfill_obligation,
10811110
vtable_methods,
10821111
substitute_normalize_and_test_predicates,
1112+
environment,
10831113
..*providers
10841114
};
10851115
}

src/librustc/traits/structural_impls.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,43 @@ EnumTypeFoldableImpl! {
658658
}
659659
}
660660

661-
impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<traits::Clause<'tcx>> {
661+
BraceStructTypeFoldableImpl! {
662+
impl<'tcx> TypeFoldable<'tcx> for traits::Environment<'tcx> { clauses }
663+
}
664+
665+
BraceStructTypeFoldableImpl! {
666+
impl<'tcx, G> TypeFoldable<'tcx> for traits::InEnvironment<'tcx, G> {
667+
environment,
668+
goal
669+
} where G: TypeFoldable<'tcx>
670+
}
671+
672+
impl<'a, 'tcx> Lift<'tcx> for traits::Environment<'a> {
673+
type Lifted = traits::Environment<'tcx>;
674+
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
675+
tcx.lift(&self.clauses).map(|clauses| {
676+
traits::Environment {
677+
clauses,
678+
}
679+
})
680+
}
681+
}
682+
683+
impl<'a, 'tcx, G: Lift<'tcx>> Lift<'tcx> for traits::InEnvironment<'a, G> {
684+
type Lifted = traits::InEnvironment<'tcx, G::Lifted>;
685+
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
686+
tcx.lift(&self.environment).and_then(|environment| {
687+
tcx.lift(&self.goal).map(|goal| {
688+
traits::InEnvironment {
689+
environment,
690+
goal,
691+
}
692+
})
693+
})
694+
}
695+
}
696+
697+
impl<'tcx> TypeFoldable<'tcx> for traits::Clauses<'tcx> {
662698
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
663699
let v = self.iter()
664700
.map(|t| t.fold_with(folder))

src/librustc/ty/query/config.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use dep_graph::SerializedDepNodeIndex;
1212
use dep_graph::DepNode;
1313
use hir::def_id::{CrateNum, DefId, DefIndex};
1414
use mir::interpret::GlobalId;
15+
use traits;
1516
use traits::query::{
1617
CanonicalPredicateGoal, CanonicalProjectionGoal, CanonicalTyGoal, CanonicalTypeOpEqGoal,
1718
CanonicalTypeOpNormalizeGoal, CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal,
@@ -826,8 +827,14 @@ impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for<'tcx> {
826827
}
827828

828829
impl<'tcx> QueryDescription<'tcx> for queries::program_clauses_for_env<'tcx> {
829-
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: ty::ParamEnv<'tcx>) -> Cow<'static, str> {
830-
"generating chalk-style clauses for param env".into()
830+
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: traits::Environment<'tcx>) -> Cow<'static, str> {
831+
"generating chalk-style clauses for environment".into()
832+
}
833+
}
834+
835+
impl<'tcx> QueryDescription<'tcx> for queries::environment<'tcx> {
836+
fn describe(_tcx: TyCtxt<'_, '_, '_>, _: DefId) -> Cow<'static, str> {
837+
"return a chalk-style environment".into()
831838
}
832839
}
833840

src/librustc/ty/query/keys.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
1313
use infer::canonical::Canonical;
1414
use hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex};
15+
use traits;
1516
use ty::{self, Ty, TyCtxt};
1617
use ty::subst::Substs;
1718
use ty::fast_reject::SimplifiedType;
@@ -181,6 +182,15 @@ impl<'tcx, T: Key> Key for ty::ParamEnvAnd<'tcx, T> {
181182
}
182183
}
183184

185+
impl<'tcx> Key for traits::Environment<'tcx> {
186+
fn query_crate(&self) -> CrateNum {
187+
LOCAL_CRATE
188+
}
189+
fn default_span(&self, _: TyCtxt<'_, '_, '_>) -> Span {
190+
DUMMY_SP
191+
}
192+
}
193+
184194
impl Key for InternedString {
185195
fn query_crate(&self) -> CrateNum {
186196
LOCAL_CRATE

src/librustc/ty/query/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ define_queries! { <'tcx>
377377
// might want to use `reveal_all()` method to change modes.
378378
[] fn param_env: ParamEnv(DefId) -> ty::ParamEnv<'tcx>,
379379

380+
[] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
381+
380382
// Trait selection queries. These are best used by invoking `ty.moves_by_default()`,
381383
// `ty.is_copy()`, etc, since that will prune the environment where possible.
382384
[] fn is_copy_raw: is_copy_dep_node(ty::ParamEnvAnd<'tcx, Ty<'tcx>>) -> bool,
@@ -664,7 +666,7 @@ define_queries! { <'tcx>
664666
[] fn program_clauses_for: ProgramClausesFor(DefId) -> Clauses<'tcx>,
665667

666668
[] fn program_clauses_for_env: ProgramClausesForEnv(
667-
ty::ParamEnv<'tcx>
669+
traits::Environment<'tcx>
668670
) -> Clauses<'tcx>,
669671
},
670672

src/librustc/ty/query/plumbing.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ pub fn force_from_dep_node<'a, 'gcx, 'lcx>(tcx: TyCtxt<'a, 'gcx, 'lcx>,
11561156
DepKind::CheckMatch => { force!(check_match, def_id!()); }
11571157

11581158
DepKind::ParamEnv => { force!(param_env, def_id!()); }
1159+
DepKind::Environment => { force!(environment, def_id!()); }
11591160
DepKind::DescribeDef => { force!(describe_def, def_id!()); }
11601161
DepKind::DefSpan => { force!(def_span, def_id!()); }
11611162
DepKind::LookupStability => { force!(lookup_stability, def_id!()); }

0 commit comments

Comments
 (0)