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

Add chalk rules related to associated type defs #54909

Merged
merged 3 commits into from
Oct 11, 2018
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 src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "chalk-engine"
version = "0.7.0"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -1898,7 +1898,7 @@ dependencies = [
"backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"chalk-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chalk-engine 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"flate2 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fmt_macros 0.0.0",
"graphviz 0.0.0",
Expand Down Expand Up @@ -2434,7 +2434,7 @@ name = "rustc_traits"
version = "0.0.0"
dependencies = [
"bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
"chalk-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"chalk-engine 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"graphviz 0.0.0",
"log 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc 0.0.0",
Expand Down Expand Up @@ -3195,7 +3195,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum cargo_metadata 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d6809b327f87369e6f3651efd2c5a96c49847a3ed2559477ecba79014751ee1"
"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16"
"checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3"
"checksum chalk-engine 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "25ce2f28f55ed544a2a3756b7acf41dd7d6f27acffb2086439950925506af7d0"
"checksum chalk-engine 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6749eb72e7d4355d944a99f15fbaea701b978c18c5e184a025fcde942b0c9779"
"checksum chalk-macros 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "295635afd6853aa9f20baeb7f0204862440c0fe994c5a253d5f479dac41d047e"
"checksum chrono 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6962c635d530328acc53ac6a955e83093fedc91c5809dfac1fa60fa470830a37"
"checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e"
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ syntax_pos = { path = "../libsyntax_pos" }
backtrace = "0.3.3"
parking_lot = "0.6"
byteorder = { version = "1.1", features = ["i128"]}
chalk-engine = { version = "0.7.0", default-features=false }
chalk-engine = { version = "0.8.0", default-features=false }
rustc_fs_util = { path = "../librustc_fs_util" }
smallvec = { version = "0.6.5", features = ["union"] }

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,7 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for traits::Goal<'tcx> {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
use traits::Goal::*;
use traits::GoalKind::*;

mem::discriminant(self).hash_stable(hcx, hasher);
match self {
Expand Down
22 changes: 12 additions & 10 deletions src/librustc/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,31 +318,33 @@ pub enum QuantifierKind {
}

#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
pub enum Goal<'tcx> {
Implies(Clauses<'tcx>, &'tcx Goal<'tcx>),
And(&'tcx Goal<'tcx>, &'tcx Goal<'tcx>),
Not(&'tcx Goal<'tcx>),
pub enum GoalKind<'tcx> {
Implies(Clauses<'tcx>, Goal<'tcx>),
And(Goal<'tcx>, Goal<'tcx>),
Not(Goal<'tcx>),
DomainGoal(DomainGoal<'tcx>),
Quantified(QuantifierKind, ty::Binder<&'tcx Goal<'tcx>>),
Quantified(QuantifierKind, ty::Binder<Goal<'tcx>>),
CannotProve,
}

pub type Goal<'tcx> = &'tcx GoalKind<'tcx>;

pub type Goals<'tcx> = &'tcx List<Goal<'tcx>>;

impl<'tcx> DomainGoal<'tcx> {
pub fn into_goal(self) -> Goal<'tcx> {
Goal::DomainGoal(self)
pub fn into_goal(self) -> GoalKind<'tcx> {
GoalKind::DomainGoal(self)
}
}

impl<'tcx> Goal<'tcx> {
impl<'tcx> GoalKind<'tcx> {
pub fn from_poly_domain_goal<'a>(
domain_goal: PolyDomainGoal<'tcx>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
) -> Goal<'tcx> {
) -> GoalKind<'tcx> {
match domain_goal.no_late_bound_regions() {
Some(p) => p.into_goal(),
None => Goal::Quantified(
None => GoalKind::Quantified(
QuantifierKind::Universal,
domain_goal.map_bound(|p| tcx.mk_goal(p.into_goal()))
),
Expand Down
34 changes: 17 additions & 17 deletions src/librustc/traits/structural_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ impl fmt::Display for traits::QuantifierKind {

impl<'tcx> fmt::Display for traits::Goal<'tcx> {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
use traits::Goal::*;
use traits::GoalKind::*;

match self {
Implies(hypotheses, goal) => {
Expand Down Expand Up @@ -598,25 +598,25 @@ CloneTypeFoldableAndLiftImpls! {
}

EnumTypeFoldableImpl! {
impl<'tcx> TypeFoldable<'tcx> for traits::Goal<'tcx> {
(traits::Goal::Implies)(hypotheses, goal),
(traits::Goal::And)(goal1, goal2),
(traits::Goal::Not)(goal),
(traits::Goal::DomainGoal)(domain_goal),
(traits::Goal::Quantified)(qkind, goal),
(traits::Goal::CannotProve),
impl<'tcx> TypeFoldable<'tcx> for traits::GoalKind<'tcx> {
(traits::GoalKind::Implies)(hypotheses, goal),
(traits::GoalKind::And)(goal1, goal2),
(traits::GoalKind::Not)(goal),
(traits::GoalKind::DomainGoal)(domain_goal),
(traits::GoalKind::Quantified)(qkind, goal),
(traits::GoalKind::CannotProve),
}
}

EnumLiftImpl! {
impl<'a, 'tcx> Lift<'tcx> for traits::Goal<'a> {
type Lifted = traits::Goal<'tcx>;
(traits::Goal::Implies)(hypotheses, goal),
(traits::Goal::And)(goal1, goal2),
(traits::Goal::Not)(goal),
(traits::Goal::DomainGoal)(domain_goal),
(traits::Goal::Quantified)(kind, goal),
(traits::Goal::CannotProve),
impl<'a, 'tcx> Lift<'tcx> for traits::GoalKind<'a> {
type Lifted = traits::GoalKind<'tcx>;
(traits::GoalKind::Implies)(hypotheses, goal),
(traits::GoalKind::And)(goal1, goal2),
(traits::GoalKind::Not)(goal),
(traits::GoalKind::DomainGoal)(domain_goal),
(traits::GoalKind::Quantified)(kind, goal),
(traits::GoalKind::CannotProve),
}
}

Expand All @@ -633,7 +633,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List<traits::Goal<'tcx>> {
}
}

impl<'tcx> TypeFoldable<'tcx> for &'tcx traits::Goal<'tcx> {
impl<'tcx> TypeFoldable<'tcx> for traits::Goal<'tcx> {
fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self {
let v = (**self).fold_with(folder);
folder.tcx().mk_goal(v)
Expand Down
29 changes: 17 additions & 12 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use mir::interpret::Allocation;
use ty::subst::{CanonicalSubsts, Kind, Substs, Subst};
use ty::ReprOptions;
use traits;
use traits::{Clause, Clauses, Goal, Goals};
use traits::{Clause, Clauses, GoalKind, Goal, Goals};
use ty::{self, Ty, TypeAndMut};
use ty::{TyS, TyKind, List};
use ty::{AdtKind, AdtDef, ClosureSubsts, GeneratorSubsts, Region, Const};
Expand Down Expand Up @@ -143,7 +143,8 @@ pub struct CtxtInterners<'tcx> {
predicates: InternedSet<'tcx, List<Predicate<'tcx>>>,
const_: InternedSet<'tcx, Const<'tcx>>,
clauses: InternedSet<'tcx, List<Clause<'tcx>>>,
goals: InternedSet<'tcx, List<Goal<'tcx>>>,
goal: InternedSet<'tcx, GoalKind<'tcx>>,
goal_list: InternedSet<'tcx, List<Goal<'tcx>>>,
}

impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
Expand All @@ -159,7 +160,8 @@ impl<'gcx: 'tcx, 'tcx> CtxtInterners<'tcx> {
predicates: Default::default(),
const_: Default::default(),
clauses: Default::default(),
goals: Default::default(),
goal: Default::default(),
goal_list: Default::default(),
}
}

Expand Down Expand Up @@ -1731,9 +1733,9 @@ impl<'a, 'tcx> Lift<'tcx> for Region<'a> {
}
}

impl<'a, 'tcx> Lift<'tcx> for &'a Goal<'a> {
type Lifted = &'tcx Goal<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<&'tcx Goal<'tcx>> {
impl<'a, 'tcx> Lift<'tcx> for Goal<'a> {
type Lifted = Goal<'tcx>;
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Goal<'tcx>> {
if tcx.interners.arena.in_arena(*self as *const _) {
return Some(unsafe { mem::transmute(*self) });
}
Expand Down Expand Up @@ -2304,6 +2306,12 @@ impl<'tcx> Borrow<RegionKind> for Interned<'tcx, RegionKind> {
}
}

impl<'tcx: 'lcx, 'lcx> Borrow<GoalKind<'lcx>> for Interned<'tcx, GoalKind<'tcx>> {
fn borrow<'a>(&'a self) -> &'a GoalKind<'lcx> {
&self.0
}
}

impl<'tcx: 'lcx, 'lcx> Borrow<[ExistentialPredicate<'lcx>]>
for Interned<'tcx, List<ExistentialPredicate<'tcx>>> {
fn borrow<'a>(&'a self) -> &'a [ExistentialPredicate<'lcx>] {
Expand Down Expand Up @@ -2419,7 +2427,8 @@ pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {

direct_interners!('tcx,
region: mk_region(|r: &RegionKind| r.keep_in_local_tcx()) -> RegionKind,
const_: mk_const(|c: &Const<'_>| keep_local(&c.ty) || keep_local(&c.val)) -> Const<'tcx>
const_: mk_const(|c: &Const<'_>| keep_local(&c.ty) || keep_local(&c.val)) -> Const<'tcx>,
goal: mk_goal(|c: &GoalKind<'_>| keep_local(c)) -> GoalKind<'tcx>
);

macro_rules! slice_interners {
Expand All @@ -2438,7 +2447,7 @@ slice_interners!(
type_list: _intern_type_list(Ty),
substs: _intern_substs(Kind),
clauses: _intern_clauses(Clause),
goals: _intern_goals(Goal)
goal_list: _intern_goals(Goal)
);

// This isn't a perfect fit: CanonicalVarInfo slices are always
Expand Down Expand Up @@ -2818,10 +2827,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
iter.intern_with(|xs| self.intern_goals(xs))
}

pub fn mk_goal(self, goal: Goal<'tcx>) -> &'tcx Goal<'_> {
&self.intern_goals(&[goal])[0]
}

pub fn lint_hir<S: Into<MultiSpan>>(self,
lint: &'static Lint,
hir_id: HirId,
Expand Down
5 changes: 4 additions & 1 deletion src/librustc/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ impl FlagComputation {
self.add_projection_ty(data);
}

&ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
&ty::UnnormalizedProjection(ref data) => {
self.add_flags(TypeFlags::HAS_PROJECTION);
self.add_projection_ty(data);
},

&ty::Opaque(_, substs) => {
self.add_flags(TypeFlags::HAS_PROJECTION);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ rustc = { path = "../librustc" }
rustc_data_structures = { path = "../librustc_data_structures" }
syntax = { path = "../libsyntax" }
syntax_pos = { path = "../libsyntax_pos" }
chalk-engine = { version = "0.7.0", default-features=false }
chalk-engine = { version = "0.8.0", default-features=false }
smallvec = { version = "0.6.5", features = ["union"] }
41 changes: 21 additions & 20 deletions src/librustc_traits/chalk_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rustc::traits::{
ExClauseFold,
ExClauseLift,
Goal,
GoalKind,
ProgramClause,
QuantifierKind
};
Expand Down Expand Up @@ -92,7 +93,7 @@ impl context::Context for ChalkArenas<'tcx> {

type DomainGoal = DomainGoal<'tcx>;

type BindersGoal = ty::Binder<&'tcx Goal<'tcx>>;
type BindersGoal = ty::Binder<Goal<'tcx>>;

type Parameter = Kind<'tcx>;

Expand All @@ -102,14 +103,6 @@ impl context::Context for ChalkArenas<'tcx> {

type UnificationResult = InferOk<'tcx, ()>;

fn into_goal(domain_goal: DomainGoal<'tcx>) -> Goal<'tcx> {
Goal::DomainGoal(domain_goal)
}

fn cannot_prove() -> Goal<'tcx> {
Goal::CannotProve
}

fn goal_in_environment(
env: &ty::ParamEnv<'tcx>,
goal: Goal<'tcx>,
Expand Down Expand Up @@ -251,15 +244,23 @@ impl context::ContextOps<ChalkArenas<'gcx>> for ChalkContext<'cx, 'gcx> {
impl context::InferenceTable<ChalkArenas<'gcx>, ChalkArenas<'tcx>>
for ChalkInferenceContext<'cx, 'gcx, 'tcx>
{
fn into_goal(&self, domain_goal: DomainGoal<'tcx>) -> Goal<'tcx> {
self.infcx.tcx.mk_goal(GoalKind::DomainGoal(domain_goal))
}

fn cannot_prove(&self) -> Goal<'tcx> {
self.infcx.tcx.mk_goal(GoalKind::CannotProve)
}

fn into_hh_goal(&mut self, goal: Goal<'tcx>) -> ChalkHhGoal<'tcx> {
match goal {
Goal::Implies(..) => panic!("FIXME rust-lang-nursery/chalk#94"),
Goal::And(left, right) => HhGoal::And(*left, *right),
Goal::Not(subgoal) => HhGoal::Not(*subgoal),
Goal::DomainGoal(d) => HhGoal::DomainGoal(d),
Goal::Quantified(QuantifierKind::Universal, binder) => HhGoal::ForAll(binder),
Goal::Quantified(QuantifierKind::Existential, binder) => HhGoal::Exists(binder),
Goal::CannotProve => HhGoal::CannotProve,
match *goal {
GoalKind::Implies(..) => panic!("FIXME rust-lang-nursery/chalk#94"),
GoalKind::And(left, right) => HhGoal::And(left, right),
GoalKind::Not(subgoal) => HhGoal::Not(subgoal),
GoalKind::DomainGoal(d) => HhGoal::DomainGoal(d),
GoalKind::Quantified(QuantifierKind::Universal, binder) => HhGoal::ForAll(binder),
GoalKind::Quantified(QuantifierKind::Existential, binder) => HhGoal::Exists(binder),
GoalKind::CannotProve => HhGoal::CannotProve,
}
}

Expand Down Expand Up @@ -363,21 +364,21 @@ impl context::UnificationOps<ChalkArenas<'gcx>, ChalkArenas<'tcx>>

fn instantiate_binders_universally(
&mut self,
_arg: &ty::Binder<&'tcx Goal<'tcx>>,
_arg: &ty::Binder<Goal<'tcx>>,
) -> Goal<'tcx> {
panic!("FIXME -- universal instantiation needs sgrif's branch")
}

fn instantiate_binders_existentially(
&mut self,
arg: &ty::Binder<&'tcx Goal<'tcx>>,
arg: &ty::Binder<Goal<'tcx>>,
) -> Goal<'tcx> {
let (value, _map) = self.infcx.replace_late_bound_regions_with_fresh_var(
DUMMY_SP,
LateBoundRegionConversionTime::HigherRankedType,
arg,
);
*value
value
}

fn debug_ex_clause(&mut self, value: &'v ChalkExClause<'tcx>) -> Box<dyn Debug + 'v> {
Expand Down
Loading