Update chalk

This commit is contained in:
Jack Huey 2020-05-26 20:19:19 -04:00
parent 16dd584e11
commit 6aa2e9d978
8 changed files with 221 additions and 195 deletions

View File

@ -432,10 +432,18 @@ dependencies = [
"rustc-std-workspace-core",
]
[[package]]
name = "chalk-base"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
dependencies = [
"lazy_static 1.4.0",
]
[[package]]
name = "chalk-derive"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3"
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
dependencies = [
"proc-macro2 1.0.3",
"quote 1.0.2",
@ -446,52 +454,33 @@ dependencies = [
[[package]]
name = "chalk-engine"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3"
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
dependencies = [
"chalk-macros",
"chalk-base",
"chalk-derive",
"chalk-ir",
"rustc-hash",
]
[[package]]
name = "chalk-ir"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3"
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
dependencies = [
"chalk-base",
"chalk-derive",
"chalk-engine",
"chalk-macros",
]
[[package]]
name = "chalk-macros"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3"
dependencies = [
"lazy_static",
]
[[package]]
name = "chalk-rust-ir"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3"
dependencies = [
"chalk-derive",
"chalk-engine",
"chalk-ir",
"chalk-macros",
]
[[package]]
name = "chalk-solve"
version = "0.10.1-dev"
source = "git+https://github.com/rust-lang/chalk.git?rev=3e9c2503ae9c5277c2acb74624dc267876dd89b3#3e9c2503ae9c5277c2acb74624dc267876dd89b3"
source = "git+https://github.com/rust-lang/chalk.git?rev=f4977ab4c781e4f3b7fdb9310edbdab6daf56e29#f4977ab4c781e4f3b7fdb9310edbdab6daf56e29"
dependencies = [
"chalk-base",
"chalk-derive",
"chalk-engine",
"chalk-ir",
"chalk-macros",
"chalk-rust-ir",
"ena 0.13.1",
"ena 0.14.0",
"itertools 0.9.0",
"petgraph",
"rustc-hash",
@ -1175,9 +1164,9 @@ dependencies = [
[[package]]
name = "fixedbitset"
version = "0.1.9"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33"
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
[[package]]
name = "flate2"
@ -2364,12 +2353,6 @@ dependencies = [
"vcpkg",
]
[[package]]
name = "ordermap"
version = "0.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
[[package]]
name = "ordslice"
version = "0.3.0"
@ -2540,12 +2523,12 @@ dependencies = [
[[package]]
name = "petgraph"
version = "0.4.13"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c3659d1ee90221741f65dd128d9998311b0e40c5d3c23a62445938214abce4f"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"ordermap",
"indexmap",
]
[[package]]
@ -3493,12 +3476,9 @@ dependencies = [
[[package]]
name = "rustc-hash"
version = "1.0.1"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7540fc8b0c49f096ee9c961cda096467dce8084bec6bdca2fc83895fd9b28cb8"
dependencies = [
"byteorder",
]
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "rustc-main"
@ -4367,7 +4347,6 @@ name = "rustc_traits"
version = "0.0.0"
dependencies = [
"chalk-ir",
"chalk-rust-ir",
"chalk-solve",
"log",
"rustc_ast",

View File

@ -23,7 +23,7 @@ crossbeam-utils = { version = "0.7", features = ["nightly"] }
stable_deref_trait = "1.0.0"
rayon = { version = "0.3.0", package = "rustc-rayon" }
rayon-core = { version = "0.3.0", package = "rustc-rayon-core" }
rustc-hash = "1.0.1"
rustc-hash = "1.1.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_index = { path = "../librustc_index", package = "rustc_index" }
bitflags = "1.2.1"

View File

@ -30,7 +30,7 @@ rustc_serialize = { path = "../librustc_serialize" }
rustc_ast = { path = "../librustc_ast" }
rustc_span = { path = "../librustc_span" }
byteorder = { version = "1.3" }
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" }
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
#chalk-ir = "0.10.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "0.7.1"

View File

@ -5,8 +5,6 @@
//! its name suggest, is to provide an abstraction boundary for creating
//! interned Chalk types.
use chalk_ir::{GoalData, Parameter};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
use rustc_middle::ty::{self, Ty, TyCtxt};
@ -79,16 +77,19 @@ impl fmt::Debug for RustInterner<'_> {
impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
type InternedType = Box<chalk_ir::TyData<Self>>;
type InternedLifetime = Box<chalk_ir::LifetimeData<Self>>;
type InternedParameter = Box<chalk_ir::ParameterData<Self>>;
type InternedConst = Box<chalk_ir::ConstData<Self>>;
type InternedConcreteConst = u32;
type InternedGenericArg = Box<chalk_ir::GenericArgData<Self>>;
type InternedGoal = Box<chalk_ir::GoalData<Self>>;
type InternedGoals = Vec<chalk_ir::Goal<Self>>;
type InternedSubstitution = Vec<chalk_ir::Parameter<Self>>;
type InternedSubstitution = Vec<chalk_ir::GenericArg<Self>>;
type InternedProgramClause = Box<chalk_ir::ProgramClauseData<Self>>;
type InternedProgramClauses = Vec<chalk_ir::ProgramClause<Self>>;
type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
type InternedParameterKinds = Vec<chalk_ir::ParameterKind<()>>;
type InternedCanonicalVarKinds = Vec<chalk_ir::ParameterKind<chalk_ir::UniverseIndex>>;
type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
type DefId = RustDefId;
type InternedAdtId = RustDefId;
type Identifier = ();
fn debug_program_clause_implication(
@ -202,25 +203,39 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
&lifetime
}
fn intern_parameter(
&self,
parameter: chalk_ir::ParameterData<Self>,
) -> Self::InternedParameter {
Box::new(parameter)
fn intern_const(&self, constant: chalk_ir::ConstData<Self>) -> Self::InternedConst {
Box::new(constant)
}
fn parameter_data<'a>(
&self,
parameter: &'a Self::InternedParameter,
) -> &'a chalk_ir::ParameterData<Self> {
&parameter
fn const_data<'a>(&self, constant: &'a Self::InternedConst) -> &'a chalk_ir::ConstData<Self> {
&constant
}
fn intern_goal(&self, goal: GoalData<Self>) -> Self::InternedGoal {
fn const_eq(
&self,
_ty: &Self::InternedType,
c1: &Self::InternedConcreteConst,
c2: &Self::InternedConcreteConst,
) -> bool {
c1 == c2
}
fn intern_generic_arg(&self, data: chalk_ir::GenericArgData<Self>) -> Self::InternedGenericArg {
Box::new(data)
}
fn generic_arg_data<'a>(
&self,
data: &'a Self::InternedGenericArg,
) -> &'a chalk_ir::GenericArgData<Self> {
&data
}
fn intern_goal(&self, goal: chalk_ir::GoalData<Self>) -> Self::InternedGoal {
Box::new(goal)
}
fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a GoalData<Self> {
fn goal_data<'a>(&self, goal: &'a Self::InternedGoal) -> &'a chalk_ir::GoalData<Self> {
&goal
}
@ -237,7 +252,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
fn intern_substitution<E>(
&self,
data: impl IntoIterator<Item = Result<chalk_ir::Parameter<Self>, E>>,
data: impl IntoIterator<Item = Result<chalk_ir::GenericArg<Self>, E>>,
) -> Result<Self::InternedSubstitution, E> {
data.into_iter().collect::<Result<Vec<_>, _>>()
}
@ -245,7 +260,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
fn substitution_data<'a>(
&self,
substitution: &'a Self::InternedSubstitution,
) -> &'a [Parameter<Self>] {
) -> &'a [chalk_ir::GenericArg<Self>] {
substitution
}
@ -291,23 +306,23 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
clauses
}
fn intern_parameter_kinds<E>(
fn intern_generic_arg_kinds<E>(
&self,
data: impl IntoIterator<Item = Result<chalk_ir::ParameterKind<()>, E>>,
) -> Result<Self::InternedParameterKinds, E> {
data: impl IntoIterator<Item = Result<chalk_ir::VariableKind<Self>, E>>,
) -> Result<Self::InternedVariableKinds, E> {
data.into_iter().collect::<Result<Vec<_>, _>>()
}
fn parameter_kinds_data<'a>(
fn variable_kinds_data<'a>(
&self,
parameter_kinds: &'a Self::InternedParameterKinds,
) -> &'a [chalk_ir::ParameterKind<()>] {
parameter_kinds: &'a Self::InternedVariableKinds,
) -> &'a [chalk_ir::VariableKind<Self>] {
parameter_kinds
}
fn intern_canonical_var_kinds<E>(
&self,
data: impl IntoIterator<Item = Result<chalk_ir::ParameterKind<chalk_ir::UniverseIndex>, E>>,
data: impl IntoIterator<Item = Result<chalk_ir::CanonicalVarKind<Self>, E>>,
) -> Result<Self::InternedCanonicalVarKinds, E> {
data.into_iter().collect::<Result<Vec<_>, _>>()
}
@ -315,7 +330,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
fn canonical_var_kinds_data<'a>(
&self,
canonical_var_kinds: &'a Self::InternedCanonicalVarKinds,
) -> &'a [chalk_ir::ParameterKind<chalk_ir::UniverseIndex>] {
) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
canonical_var_kinds
}
}

View File

@ -19,9 +19,8 @@ rustc_span = { path = "../librustc_span" }
#chalk-ir = "0.10.0"
#chalk-rust-ir = "0.10.0"
#chalk-solve = "0.10.0"
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" }
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" }
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" }
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_infer = { path = "../librustc_infer" }
rustc_trait_selection = { path = "../librustc_trait_selection" }

View File

@ -38,7 +38,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn associated_ty_data(
&self,
assoc_type_id: chalk_ir::AssocTypeId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::AssociatedTyDatum<RustInterner<'tcx>>> {
) -> Arc<chalk_solve::rust_ir::AssociatedTyDatum<RustInterner<'tcx>>> {
let def_id = match assoc_type_id.0 {
RustDefId::AssocTy(def_id) => def_id,
_ => bug!("Did not use `AssocTy` variant when expecting associated type."),
@ -63,13 +63,13 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
.map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
Arc::new(chalk_rust_ir::AssociatedTyDatum {
Arc::new(chalk_solve::rust_ir::AssociatedTyDatum {
trait_id: chalk_ir::TraitId(RustDefId::Trait(trait_def_id)),
id: assoc_type_id,
name: (),
binders: chalk_ir::Binders::new(
binders,
chalk_rust_ir::AssociatedTyDatumBound { bounds: vec![], where_clauses },
chalk_solve::rust_ir::AssociatedTyDatumBound { bounds: vec![], where_clauses },
),
})
}
@ -77,7 +77,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn trait_datum(
&self,
trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::TraitDatum<RustInterner<'tcx>>> {
) -> Arc<chalk_solve::rust_ir::TraitDatum<RustInterner<'tcx>>> {
let def_id = match trait_id.0 {
RustDefId::Trait(def_id) => def_id,
_ => bug!("Did not use `Trait` variant when expecting trait."),
@ -94,21 +94,21 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let well_known =
if self.tcx.lang_items().sized_trait().map(|t| def_id == t).unwrap_or(false) {
Some(chalk_rust_ir::WellKnownTrait::SizedTrait)
Some(chalk_solve::rust_ir::WellKnownTrait::SizedTrait)
} else if self.tcx.lang_items().copy_trait().map(|t| def_id == t).unwrap_or(false) {
Some(chalk_rust_ir::WellKnownTrait::CopyTrait)
Some(chalk_solve::rust_ir::WellKnownTrait::CopyTrait)
} else if self.tcx.lang_items().clone_trait().map(|t| def_id == t).unwrap_or(false) {
Some(chalk_rust_ir::WellKnownTrait::CloneTrait)
Some(chalk_solve::rust_ir::WellKnownTrait::CloneTrait)
} else {
None
};
Arc::new(chalk_rust_ir::TraitDatum {
Arc::new(chalk_solve::rust_ir::TraitDatum {
id: trait_id,
binders: chalk_ir::Binders::new(
binders,
chalk_rust_ir::TraitDatumBound { where_clauses },
chalk_solve::rust_ir::TraitDatumBound { where_clauses },
),
flags: chalk_rust_ir::TraitFlags {
flags: chalk_solve::rust_ir::TraitFlags {
auto: trait_def.has_auto_impl,
marker: trait_def.is_marker,
upstream: !def_id.is_local(),
@ -121,10 +121,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
})
}
fn struct_datum(
fn adt_datum(
&self,
struct_id: chalk_ir::StructId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::StructDatum<RustInterner<'tcx>>> {
struct_id: chalk_ir::AdtId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::AdtDatum<RustInterner<'tcx>>> {
match struct_id.0 {
RustDefId::Adt(adt_def_id) => {
let adt_def = self.tcx.adt_def(adt_def_id);
@ -155,47 +155,64 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
// FIXME(chalk): handle enums; force_impl_for requires this
ty::AdtKind::Enum => vec![],
};
let struct_datum = Arc::new(chalk_rust_ir::StructDatum {
let struct_datum = Arc::new(chalk_solve::rust_ir::AdtDatum {
id: struct_id,
binders: chalk_ir::Binders::new(
binders,
chalk_rust_ir::StructDatumBound { fields, where_clauses },
chalk_solve::rust_ir::AdtDatumBound { fields, where_clauses },
),
flags: chalk_rust_ir::StructFlags {
flags: chalk_solve::rust_ir::AdtFlags {
upstream: !adt_def_id.is_local(),
fundamental: adt_def.is_fundamental(),
},
});
struct_datum
}
RustDefId::Array => Arc::new(chalk_rust_ir::StructDatum {
id: struct_id,
binders: chalk_ir::Binders::new(
chalk_ir::ParameterKinds::from(
&self.interner,
Some(chalk_ir::ParameterKind::Ty(())),
RustDefId::Array => {
return Arc::new(chalk_solve::rust_ir::AdtDatum {
id: struct_id,
binders: chalk_ir::Binders::new(
chalk_ir::VariableKinds::from(
&self.interner,
Some(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)),
),
chalk_solve::rust_ir::AdtDatumBound {
fields: vec![],
where_clauses: vec![],
},
),
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
),
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
}),
RustDefId::Never | RustDefId::FnDef(_) => Arc::new(chalk_rust_ir::StructDatum {
id: struct_id,
binders: chalk_ir::Binders::new(
chalk_ir::ParameterKinds::new(&self.interner),
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] },
),
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false },
}),
flags: chalk_solve::rust_ir::AdtFlags { upstream: false, fundamental: false },
});
}
RustDefId::Never | RustDefId::FnDef(_) => {
return Arc::new(chalk_solve::rust_ir::AdtDatum {
id: struct_id,
binders: chalk_ir::Binders::new(
chalk_ir::VariableKinds::new(&self.interner),
chalk_solve::rust_ir::AdtDatumBound {
fields: vec![],
where_clauses: vec![],
},
),
flags: chalk_solve::rust_ir::AdtFlags { upstream: false, fundamental: false },
});
}
v => bug!("Used not struct variant ({:?}) when expecting struct variant.", v),
}
}
fn fn_def_datum(
&self,
_fn_def_id: chalk_ir::FnDefId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::FnDefDatum<RustInterner<'tcx>>> {
unimplemented!()
}
fn impl_datum(
&self,
impl_id: chalk_ir::ImplId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::ImplDatum<RustInterner<'tcx>>> {
) -> Arc<chalk_solve::rust_ir::ImplDatum<RustInterner<'tcx>>> {
let def_id = match impl_id.0 {
RustDefId::Impl(def_id) => def_id,
_ => bug!("Did not use `Impl` variant when expecting impl."),
@ -212,15 +229,15 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
.map(|(wc, _)| wc.subst(self.tcx, bound_vars))
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
let value = chalk_rust_ir::ImplDatumBound {
let value = chalk_solve::rust_ir::ImplDatumBound {
trait_ref: trait_ref.lower_into(&self.interner),
where_clauses,
};
Arc::new(chalk_rust_ir::ImplDatum {
polarity: chalk_rust_ir::Polarity::Positive,
Arc::new(chalk_solve::rust_ir::ImplDatum {
polarity: chalk_solve::rust_ir::Polarity::Positive,
binders: chalk_ir::Binders::new(binders, value),
impl_type: chalk_rust_ir::ImplType::Local,
impl_type: chalk_solve::rust_ir::ImplType::Local,
associated_ty_value_ids: vec![],
})
}
@ -228,7 +245,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn impls_for_trait(
&self,
trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
parameters: &[chalk_ir::Parameter<RustInterner<'tcx>>],
parameters: &[chalk_ir::GenericArg<RustInterner<'tcx>>],
) -> Vec<chalk_ir::ImplId<RustInterner<'tcx>>> {
let def_id: DefId = match trait_id.0 {
RustDefId::Trait(def_id) => def_id,
@ -261,7 +278,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn impl_provided_for(
&self,
auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
struct_id: chalk_ir::StructId<RustInterner<'tcx>>,
struct_id: chalk_ir::AdtId<RustInterner<'tcx>>,
) -> bool {
let trait_def_id: DefId = match auto_trait_id.0 {
RustDefId::Trait(def_id) => def_id,
@ -296,8 +313,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn associated_ty_value(
&self,
associated_ty_id: chalk_rust_ir::AssociatedTyValueId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
associated_ty_id: chalk_solve::rust_ir::AssociatedTyValueId<RustInterner<'tcx>>,
) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
let def_id = match associated_ty_id.0 {
RustDefId::AssocTy(def_id) => def_id,
_ => bug!("Did not use `AssocTy` variant when expecting associated type."),
@ -315,12 +332,12 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
let binders = binders_for(&self.interner, bound_vars);
let ty = self.tcx.type_of(def_id);
Arc::new(chalk_rust_ir::AssociatedTyValue {
Arc::new(chalk_solve::rust_ir::AssociatedTyValue {
impl_id: chalk_ir::ImplId(RustDefId::Impl(impl_id)),
associated_ty_id: chalk_ir::AssocTypeId(RustDefId::AssocTy(def_id)),
value: chalk_ir::Binders::new(
binders,
chalk_rust_ir::AssociatedTyValueBound { ty: ty.lower_into(&self.interner) },
chalk_solve::rust_ir::AssociatedTyValueBound { ty: ty.lower_into(&self.interner) },
),
})
}
@ -339,17 +356,17 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn opaque_ty_data(
&self,
opaque_ty_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::OpaqueTyDatum<RustInterner<'tcx>>> {
) -> Arc<chalk_solve::rust_ir::OpaqueTyDatum<RustInterner<'tcx>>> {
// FIXME(chalk): actually lower opaque ty
let hidden_ty =
self.tcx.mk_ty(ty::Tuple(self.tcx.intern_substs(&[]))).lower_into(&self.interner);
let value = chalk_rust_ir::OpaqueTyDatumBound {
let value = chalk_solve::rust_ir::OpaqueTyDatumBound {
hidden_ty,
bounds: chalk_ir::Binders::new(chalk_ir::ParameterKinds::new(&self.interner), vec![]),
bounds: chalk_ir::Binders::new(chalk_ir::VariableKinds::new(&self.interner), vec![]),
};
Arc::new(chalk_rust_ir::OpaqueTyDatum {
Arc::new(chalk_solve::rust_ir::OpaqueTyDatum {
opaque_ty_id,
bound: chalk_ir::Binders::new(chalk_ir::ParameterKinds::new(&self.interner), value),
bound: chalk_ir::Binders::new(chalk_ir::VariableKinds::new(&self.interner), value),
})
}
@ -358,14 +375,14 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
/// `None` and eventually this function will be removed.
fn force_impl_for(
&self,
well_known: chalk_rust_ir::WellKnownTrait,
well_known: chalk_solve::rust_ir::WellKnownTrait,
ty: &chalk_ir::TyData<RustInterner<'tcx>>,
) -> Option<bool> {
use chalk_ir::TyData::*;
match well_known {
chalk_rust_ir::WellKnownTrait::SizedTrait => match ty {
chalk_solve::rust_ir::WellKnownTrait::SizedTrait => match ty {
Apply(apply) => match apply.name {
chalk_ir::TypeName::Struct(chalk_ir::StructId(rust_def_id)) => {
chalk_ir::TypeName::Adt(chalk_ir::AdtId(rust_def_id)) => {
use rustc_middle::traits::ChalkRustDefId::*;
match rust_def_id {
Never | Array | FnDef(_) => Some(true),
@ -390,13 +407,17 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
}
_ => None,
},
Dyn(_) | Alias(_) | Placeholder(_) | Function(_) | InferenceVar(_)
Dyn(_)
| Alias(_)
| Placeholder(_)
| Function(_)
| InferenceVar(_, _)
| BoundVar(_) => None,
},
chalk_rust_ir::WellKnownTrait::CopyTrait
| chalk_rust_ir::WellKnownTrait::CloneTrait => match ty {
chalk_solve::rust_ir::WellKnownTrait::CopyTrait
| chalk_solve::rust_ir::WellKnownTrait::CloneTrait => match ty {
Apply(apply) => match apply.name {
chalk_ir::TypeName::Struct(chalk_ir::StructId(rust_def_id)) => {
chalk_ir::TypeName::Adt(chalk_ir::AdtId(rust_def_id)) => {
use rustc_middle::traits::ChalkRustDefId::*;
match rust_def_id {
Never => Some(false),
@ -420,10 +441,14 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
}
_ => None,
},
Dyn(_) | Alias(_) | Placeholder(_) | Function(_) | InferenceVar(_)
Dyn(_)
| Alias(_)
| Placeholder(_)
| Function(_)
| InferenceVar(_, _)
| BoundVar(_) => None,
},
chalk_rust_ir::WellKnownTrait::DropTrait => None,
chalk_solve::rust_ir::WellKnownTrait::DropTrait => None,
}
}
@ -436,9 +461,9 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn well_known_trait_id(
&self,
well_known_trait: chalk_rust_ir::WellKnownTrait,
well_known_trait: chalk_solve::rust_ir::WellKnownTrait,
) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> {
use chalk_rust_ir::WellKnownTrait::*;
use chalk_solve::rust_ir::WellKnownTrait::*;
let t = match well_known_trait {
SizedTrait => self
.tcx
@ -512,13 +537,17 @@ fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
fn binders_for<'tcx>(
interner: &RustInterner<'tcx>,
bound_vars: SubstsRef<'tcx>,
) -> chalk_ir::ParameterKinds<RustInterner<'tcx>> {
chalk_ir::ParameterKinds::from(
) -> chalk_ir::VariableKinds<RustInterner<'tcx>> {
chalk_ir::VariableKinds::from(
interner,
bound_vars.iter().map(|arg| match arg.unpack() {
ty::subst::GenericArgKind::Lifetime(_re) => chalk_ir::ParameterKind::Lifetime(()),
ty::subst::GenericArgKind::Type(_ty) => chalk_ir::ParameterKind::Ty(()),
ty::subst::GenericArgKind::Const(_const) => chalk_ir::ParameterKind::Ty(()),
ty::subst::GenericArgKind::Lifetime(_re) => chalk_ir::VariableKind::Lifetime,
ty::subst::GenericArgKind::Type(_ty) => {
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)
}
ty::subst::GenericArgKind::Const(_const) => {
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General)
}
}),
)
}

View File

@ -274,7 +274,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
use TyKind::*;
let empty = || chalk_ir::Substitution::empty(interner);
let struct_ty = |def_id| chalk_ir::TypeName::Struct(chalk_ir::StructId(def_id));
let struct_ty = |def_id| chalk_ir::TypeName::Adt(chalk_ir::AdtId(def_id));
let apply = |name, substitution| {
TyData::Apply(chalk_ir::ApplicationTy { name, substitution }).intern(interner)
};
@ -314,14 +314,14 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
struct_ty(RustDefId::Array),
chalk_ir::Substitution::from1(
interner,
chalk_ir::ParameterKind::Ty(ty.lower_into(interner)).intern(interner),
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
),
),
Slice(ty) => apply(
chalk_ir::TypeName::Slice,
chalk_ir::Substitution::from1(
interner,
chalk_ir::ParameterKind::Ty(ty.lower_into(interner)).intern(interner),
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
),
),
RawPtr(ptr) => {
@ -341,9 +341,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
chalk_ir::Substitution::from(
interner,
&[
chalk_ir::ParameterKind::Lifetime(region.lower_into(interner))
chalk_ir::GenericArgData::Lifetime(region.lower_into(interner))
.intern(interner),
chalk_ir::ParameterKind::Ty(ty.lower_into(interner)).intern(interner),
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
],
),
)
@ -357,7 +357,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
substitution: chalk_ir::Substitution::from(
interner,
inputs_and_outputs.iter().map(|ty| {
chalk_ir::ParameterKind::Ty(ty.lower_into(interner)).intern(interner)
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner)
}),
),
})
@ -439,16 +439,16 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Lifetime<RustInterner<'tcx>>> for Region<'t
}
}
impl<'tcx> LowerInto<'tcx, chalk_ir::Parameter<RustInterner<'tcx>>> for GenericArg<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Parameter<RustInterner<'tcx>> {
impl<'tcx> LowerInto<'tcx, chalk_ir::GenericArg<RustInterner<'tcx>>> for GenericArg<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GenericArg<RustInterner<'tcx>> {
match self.unpack() {
ty::subst::GenericArgKind::Type(ty) => {
chalk_ir::ParameterKind::Ty(ty.lower_into(interner))
chalk_ir::GenericArgData::Ty(ty.lower_into(interner))
}
ty::subst::GenericArgKind::Lifetime(lifetime) => {
chalk_ir::ParameterKind::Lifetime(lifetime.lower_into(interner))
chalk_ir::GenericArgData::Lifetime(lifetime.lower_into(interner))
}
ty::subst::GenericArgKind::Const(_) => chalk_ir::ParameterKind::Ty(
ty::subst::GenericArgKind::Const(_) => chalk_ir::GenericArgData::Ty(
chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::Tuple(0),
substitution: chalk_ir::Substitution::empty(interner),
@ -507,7 +507,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
let where_clauses = predicates.into_iter().map(|predicate| match predicate {
ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef { def_id, substs }) => {
chalk_ir::Binders::new(
chalk_ir::ParameterKinds::new(interner),
chalk_ir::VariableKinds::new(interner),
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
trait_id: chalk_ir::TraitId(RustDefId::Trait(*def_id)),
substitution: substs.lower_into(interner),
@ -516,7 +516,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Binders<chalk_ir::QuantifiedWhereClauses<Ru
}
ty::ExistentialPredicate::Projection(_predicate) => unimplemented!(),
ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new(
chalk_ir::ParameterKinds::new(interner),
chalk_ir::VariableKinds::new(interner),
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
trait_id: chalk_ir::TraitId(RustDefId::Trait(*def_id)),
substitution: chalk_ir::Substitution::empty(interner),
@ -541,7 +541,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
interner: &RustInterner<'tcx>,
tcx: TyCtxt<'tcx>,
ty: &'a Binder<T>,
) -> (T, chalk_ir::ParameterKinds<RustInterner<'tcx>>, BTreeMap<DefId, u32>) {
) -> (T, chalk_ir::VariableKinds<RustInterner<'tcx>>, BTreeMap<DefId, u32>) {
let mut bound_vars_collector = BoundVarsCollector::new();
ty.skip_binder().visit_with(&mut bound_vars_collector);
let mut parameters = bound_vars_collector.parameters;
@ -556,25 +556,25 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor);
for var in named_parameters.values() {
parameters.insert(*var, chalk_ir::ParameterKind::Lifetime(()));
parameters.insert(*var, chalk_ir::VariableKind::Lifetime);
}
(0..parameters.len()).for_each(|i| {
parameters.get(&(i as u32)).expect("Skipped bound var index.");
});
let binders = chalk_ir::ParameterKinds::from(interner, parameters.into_iter().map(|(_, v)| v));
let binders = chalk_ir::VariableKinds::from(interner, parameters.into_iter().map(|(_, v)| v));
(new_ty, binders, named_parameters)
}
crate struct BoundVarsCollector {
crate struct BoundVarsCollector<'tcx> {
binder_index: ty::DebruijnIndex,
crate parameters: BTreeMap<u32, chalk_ir::ParameterKind<()>>,
crate parameters: BTreeMap<u32, chalk_ir::VariableKind<RustInterner<'tcx>>>,
crate named_parameters: Vec<DefId>,
}
impl BoundVarsCollector {
impl<'tcx> BoundVarsCollector<'tcx> {
crate fn new() -> Self {
BoundVarsCollector {
binder_index: ty::INNERMOST,
@ -584,7 +584,7 @@ impl BoundVarsCollector {
}
}
impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector {
impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector<'tcx> {
fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
self.binder_index.shift_in(1);
let result = t.super_visit_with(self);
@ -597,11 +597,12 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector {
ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
match self.parameters.entry(bound_ty.var.as_u32()) {
Entry::Vacant(entry) => {
entry.insert(chalk_ir::ParameterKind::Ty(()));
}
Entry::Occupied(entry) => {
entry.get().assert_ty_ref();
entry.insert(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General));
}
Entry::Occupied(entry) => match entry.get() {
chalk_ir::VariableKind::Ty(_) => {}
_ => panic!(),
},
}
}
@ -622,11 +623,12 @@ impl<'tcx> TypeVisitor<'tcx> for BoundVarsCollector {
ty::BoundRegion::BrAnon(var) => match self.parameters.entry(*var) {
Entry::Vacant(entry) => {
entry.insert(chalk_ir::ParameterKind::Lifetime(()));
}
Entry::Occupied(entry) => {
entry.get().assert_lifetime_ref();
entry.insert(chalk_ir::VariableKind::Lifetime);
}
Entry::Occupied(entry) => match entry.get() {
chalk_ir::VariableKind::Lifetime => {}
_ => panic!(),
},
},
ty::BrEnv => unimplemented!(),

View File

@ -55,25 +55,23 @@ crate fn evaluate_goal<'tcx>(
CanonicalVarKind::PlaceholderTy(_ty) => unimplemented!(),
CanonicalVarKind::PlaceholderRegion(_ui) => unimplemented!(),
CanonicalVarKind::Ty(ty) => match ty {
CanonicalTyVarKind::General(ui) => {
chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex {
counter: ui.index(),
})
}
CanonicalTyVarKind::Int | CanonicalTyVarKind::Float => {
// FIXME(chalk) - this is actually really important
// These variable kinds put some limits on the
// types that can be substituted (floats or ints).
// While it's unclear exactly the design here, we
// probably want some way to "register" these.
chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::root())
}
CanonicalTyVarKind::General(ui) => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General),
chalk_ir::UniverseIndex { counter: ui.index() },
),
CanonicalTyVarKind::Int => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::Integer),
chalk_ir::UniverseIndex::root(),
),
CanonicalTyVarKind::Float => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Ty(chalk_ir::TyKind::Float),
chalk_ir::UniverseIndex::root(),
),
},
CanonicalVarKind::Region(ui) => {
chalk_ir::ParameterKind::Lifetime(chalk_ir::UniverseIndex {
counter: ui.index(),
})
}
CanonicalVarKind::Region(ui) => chalk_ir::WithKind::new(
chalk_ir::VariableKind::Lifetime,
chalk_ir::UniverseIndex { counter: ui.index() },
),
CanonicalVarKind::Const(_ui) => unimplemented!(),
CanonicalVarKind::PlaceholderConst(_pc) => unimplemented!(),
}),
@ -101,14 +99,14 @@ crate fn evaluate_goal<'tcx>(
// essentially inverse of lowering a `GenericArg`.
let _data = p.data(&interner);
match _data {
chalk_ir::ParameterKind::Ty(_t) => {
chalk_ir::GenericArgData::Ty(_t) => {
use chalk_ir::TyData;
use rustc_ast::ast;
let _data = _t.data(&interner);
let kind = match _data {
TyData::Apply(_application_ty) => match _application_ty.name {
chalk_ir::TypeName::Struct(_struct_id) => match _struct_id.0 {
chalk_ir::TypeName::Adt(_struct_id) => match _struct_id.0 {
RustDefId::Adt(_) => unimplemented!(),
RustDefId::Never => unimplemented!(),
RustDefId::Array => unimplemented!(),
@ -139,6 +137,9 @@ crate fn evaluate_goal<'tcx>(
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
},
},
chalk_ir::TypeName::Array => unimplemented!(),
chalk_ir::TypeName::FnDef(_) => unimplemented!(),
chalk_ir::TypeName::Never => unimplemented!(),
chalk_ir::TypeName::Tuple(_size) => unimplemented!(),
chalk_ir::TypeName::Slice => unimplemented!(),
chalk_ir::TypeName::Raw(_) => unimplemented!(),
@ -160,14 +161,14 @@ crate fn evaluate_goal<'tcx>(
kind: ty::BoundTyKind::Anon,
},
),
TyData::InferenceVar(_) => unimplemented!(),
TyData::InferenceVar(_, _) => unimplemented!(),
TyData::Dyn(_) => unimplemented!(),
};
let _ty: Ty<'_> = tcx.mk_ty(kind);
let _arg: GenericArg<'_> = _ty.into();
var_values.push(_arg);
}
chalk_ir::ParameterKind::Lifetime(_l) => {
chalk_ir::GenericArgData::Lifetime(_l) => {
let _data = _l.data(&interner);
let _lifetime: Region<'_> = match _data {
chalk_ir::LifetimeData::BoundVar(_var) => {
@ -185,6 +186,7 @@ crate fn evaluate_goal<'tcx>(
let _arg: GenericArg<'_> = _lifetime.into();
var_values.push(_arg);
}
chalk_ir::GenericArgData::Const(_) => unimplemented!(),
}
});
let sol = Canonical {