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

View File

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

View File

@ -30,7 +30,7 @@ rustc_serialize = { path = "../librustc_serialize" }
rustc_ast = { path = "../librustc_ast" } rustc_ast = { path = "../librustc_ast" }
rustc_span = { path = "../librustc_span" } rustc_span = { path = "../librustc_span" }
byteorder = { version = "1.3" } 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" #chalk-ir = "0.10.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] } smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "0.7.1" measureme = "0.7.1"

View File

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

View File

@ -19,9 +19,8 @@ rustc_span = { path = "../librustc_span" }
#chalk-ir = "0.10.0" #chalk-ir = "0.10.0"
#chalk-rust-ir = "0.10.0" #chalk-rust-ir = "0.10.0"
#chalk-solve = "0.10.0" #chalk-solve = "0.10.0"
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" } chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "f4977ab4c781e4f3b7fdb9310edbdab6daf56e29" }
chalk-rust-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 = { git = "https://github.com/rust-lang/chalk.git", rev = "3e9c2503ae9c5277c2acb74624dc267876dd89b3" }
smallvec = { version = "1.0", features = ["union", "may_dangle"] } smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_infer = { path = "../librustc_infer" } rustc_infer = { path = "../librustc_infer" }
rustc_trait_selection = { path = "../librustc_trait_selection" } 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( fn associated_ty_data(
&self, &self,
assoc_type_id: chalk_ir::AssocTypeId<RustInterner<'tcx>>, 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 { let def_id = match assoc_type_id.0 {
RustDefId::AssocTy(def_id) => def_id, RustDefId::AssocTy(def_id) => def_id,
_ => bug!("Did not use `AssocTy` variant when expecting associated type."), _ => 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)) .map(|(wc, _)| wc.subst(self.tcx, &bound_vars))
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect(); .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)), trait_id: chalk_ir::TraitId(RustDefId::Trait(trait_def_id)),
id: assoc_type_id, id: assoc_type_id,
name: (), name: (),
binders: chalk_ir::Binders::new( binders: chalk_ir::Binders::new(
binders, 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( fn trait_datum(
&self, &self,
trait_id: chalk_ir::TraitId<RustInterner<'tcx>>, 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 { let def_id = match trait_id.0 {
RustDefId::Trait(def_id) => def_id, RustDefId::Trait(def_id) => def_id,
_ => bug!("Did not use `Trait` variant when expecting trait."), _ => 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 = let well_known =
if self.tcx.lang_items().sized_trait().map(|t| def_id == t).unwrap_or(false) { 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) { } 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) { } 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 { } else {
None None
}; };
Arc::new(chalk_rust_ir::TraitDatum { Arc::new(chalk_solve::rust_ir::TraitDatum {
id: trait_id, id: trait_id,
binders: chalk_ir::Binders::new( binders: chalk_ir::Binders::new(
binders, 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, auto: trait_def.has_auto_impl,
marker: trait_def.is_marker, marker: trait_def.is_marker,
upstream: !def_id.is_local(), 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, &self,
struct_id: chalk_ir::StructId<RustInterner<'tcx>>, struct_id: chalk_ir::AdtId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::StructDatum<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::AdtDatum<RustInterner<'tcx>>> {
match struct_id.0 { match struct_id.0 {
RustDefId::Adt(adt_def_id) => { RustDefId::Adt(adt_def_id) => {
let adt_def = self.tcx.adt_def(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 // FIXME(chalk): handle enums; force_impl_for requires this
ty::AdtKind::Enum => vec![], 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, id: struct_id,
binders: chalk_ir::Binders::new( binders: chalk_ir::Binders::new(
binders, 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(), upstream: !adt_def_id.is_local(),
fundamental: adt_def.is_fundamental(), fundamental: adt_def.is_fundamental(),
}, },
}); });
struct_datum struct_datum
} }
RustDefId::Array => Arc::new(chalk_rust_ir::StructDatum { RustDefId::Array => {
id: struct_id, return Arc::new(chalk_solve::rust_ir::AdtDatum {
binders: chalk_ir::Binders::new( id: struct_id,
chalk_ir::ParameterKinds::from( binders: chalk_ir::Binders::new(
&self.interner, chalk_ir::VariableKinds::from(
Some(chalk_ir::ParameterKind::Ty(())), &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_solve::rust_ir::AdtFlags { upstream: false, fundamental: false },
), });
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false }, }
}), RustDefId::Never | RustDefId::FnDef(_) => {
RustDefId::Never | RustDefId::FnDef(_) => Arc::new(chalk_rust_ir::StructDatum { return Arc::new(chalk_solve::rust_ir::AdtDatum {
id: struct_id, id: struct_id,
binders: chalk_ir::Binders::new( binders: chalk_ir::Binders::new(
chalk_ir::ParameterKinds::new(&self.interner), chalk_ir::VariableKinds::new(&self.interner),
chalk_rust_ir::StructDatumBound { fields: vec![], where_clauses: vec![] }, chalk_solve::rust_ir::AdtDatumBound {
), fields: vec![],
flags: chalk_rust_ir::StructFlags { upstream: false, fundamental: false }, where_clauses: vec![],
}), },
),
flags: chalk_solve::rust_ir::AdtFlags { upstream: false, fundamental: false },
});
}
v => bug!("Used not struct variant ({:?}) when expecting struct variant.", v), 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( fn impl_datum(
&self, &self,
impl_id: chalk_ir::ImplId<RustInterner<'tcx>>, 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 { let def_id = match impl_id.0 {
RustDefId::Impl(def_id) => def_id, RustDefId::Impl(def_id) => def_id,
_ => bug!("Did not use `Impl` variant when expecting impl."), _ => 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)) .map(|(wc, _)| wc.subst(self.tcx, bound_vars))
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect(); .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), trait_ref: trait_ref.lower_into(&self.interner),
where_clauses, where_clauses,
}; };
Arc::new(chalk_rust_ir::ImplDatum { Arc::new(chalk_solve::rust_ir::ImplDatum {
polarity: chalk_rust_ir::Polarity::Positive, polarity: chalk_solve::rust_ir::Polarity::Positive,
binders: chalk_ir::Binders::new(binders, value), 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![], associated_ty_value_ids: vec![],
}) })
} }
@ -228,7 +245,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn impls_for_trait( fn impls_for_trait(
&self, &self,
trait_id: chalk_ir::TraitId<RustInterner<'tcx>>, 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>>> { ) -> Vec<chalk_ir::ImplId<RustInterner<'tcx>>> {
let def_id: DefId = match trait_id.0 { let def_id: DefId = match trait_id.0 {
RustDefId::Trait(def_id) => def_id, RustDefId::Trait(def_id) => def_id,
@ -261,7 +278,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn impl_provided_for( fn impl_provided_for(
&self, &self,
auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>, auto_trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
struct_id: chalk_ir::StructId<RustInterner<'tcx>>, struct_id: chalk_ir::AdtId<RustInterner<'tcx>>,
) -> bool { ) -> bool {
let trait_def_id: DefId = match auto_trait_id.0 { let trait_def_id: DefId = match auto_trait_id.0 {
RustDefId::Trait(def_id) => def_id, RustDefId::Trait(def_id) => def_id,
@ -296,8 +313,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
fn associated_ty_value( fn associated_ty_value(
&self, &self,
associated_ty_id: chalk_rust_ir::AssociatedTyValueId<RustInterner<'tcx>>, associated_ty_id: chalk_solve::rust_ir::AssociatedTyValueId<RustInterner<'tcx>>,
) -> Arc<chalk_rust_ir::AssociatedTyValue<RustInterner<'tcx>>> { ) -> Arc<chalk_solve::rust_ir::AssociatedTyValue<RustInterner<'tcx>>> {
let def_id = match associated_ty_id.0 { let def_id = match associated_ty_id.0 {
RustDefId::AssocTy(def_id) => def_id, RustDefId::AssocTy(def_id) => def_id,
_ => bug!("Did not use `AssocTy` variant when expecting associated type."), _ => 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 binders = binders_for(&self.interner, bound_vars);
let ty = self.tcx.type_of(def_id); 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)), impl_id: chalk_ir::ImplId(RustDefId::Impl(impl_id)),
associated_ty_id: chalk_ir::AssocTypeId(RustDefId::AssocTy(def_id)), associated_ty_id: chalk_ir::AssocTypeId(RustDefId::AssocTy(def_id)),
value: chalk_ir::Binders::new( value: chalk_ir::Binders::new(
binders, 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( fn opaque_ty_data(
&self, &self,
opaque_ty_id: chalk_ir::OpaqueTyId<RustInterner<'tcx>>, 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 // FIXME(chalk): actually lower opaque ty
let hidden_ty = let hidden_ty =
self.tcx.mk_ty(ty::Tuple(self.tcx.intern_substs(&[]))).lower_into(&self.interner); 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, 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, 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. /// `None` and eventually this function will be removed.
fn force_impl_for( fn force_impl_for(
&self, &self,
well_known: chalk_rust_ir::WellKnownTrait, well_known: chalk_solve::rust_ir::WellKnownTrait,
ty: &chalk_ir::TyData<RustInterner<'tcx>>, ty: &chalk_ir::TyData<RustInterner<'tcx>>,
) -> Option<bool> { ) -> Option<bool> {
use chalk_ir::TyData::*; use chalk_ir::TyData::*;
match well_known { match well_known {
chalk_rust_ir::WellKnownTrait::SizedTrait => match ty { chalk_solve::rust_ir::WellKnownTrait::SizedTrait => match ty {
Apply(apply) => match apply.name { 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::*; use rustc_middle::traits::ChalkRustDefId::*;
match rust_def_id { match rust_def_id {
Never | Array | FnDef(_) => Some(true), Never | Array | FnDef(_) => Some(true),
@ -390,13 +407,17 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
} }
_ => None, _ => None,
}, },
Dyn(_) | Alias(_) | Placeholder(_) | Function(_) | InferenceVar(_) Dyn(_)
| Alias(_)
| Placeholder(_)
| Function(_)
| InferenceVar(_, _)
| BoundVar(_) => None, | BoundVar(_) => None,
}, },
chalk_rust_ir::WellKnownTrait::CopyTrait chalk_solve::rust_ir::WellKnownTrait::CopyTrait
| chalk_rust_ir::WellKnownTrait::CloneTrait => match ty { | chalk_solve::rust_ir::WellKnownTrait::CloneTrait => match ty {
Apply(apply) => match apply.name { 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::*; use rustc_middle::traits::ChalkRustDefId::*;
match rust_def_id { match rust_def_id {
Never => Some(false), Never => Some(false),
@ -420,10 +441,14 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
} }
_ => None, _ => None,
}, },
Dyn(_) | Alias(_) | Placeholder(_) | Function(_) | InferenceVar(_) Dyn(_)
| Alias(_)
| Placeholder(_)
| Function(_)
| InferenceVar(_, _)
| BoundVar(_) => None, | 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( fn well_known_trait_id(
&self, &self,
well_known_trait: chalk_rust_ir::WellKnownTrait, well_known_trait: chalk_solve::rust_ir::WellKnownTrait,
) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> { ) -> Option<chalk_ir::TraitId<RustInterner<'tcx>>> {
use chalk_rust_ir::WellKnownTrait::*; use chalk_solve::rust_ir::WellKnownTrait::*;
let t = match well_known_trait { let t = match well_known_trait {
SizedTrait => self SizedTrait => self
.tcx .tcx
@ -512,13 +537,17 @@ fn bound_vars_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
fn binders_for<'tcx>( fn binders_for<'tcx>(
interner: &RustInterner<'tcx>, interner: &RustInterner<'tcx>,
bound_vars: SubstsRef<'tcx>, bound_vars: SubstsRef<'tcx>,
) -> chalk_ir::ParameterKinds<RustInterner<'tcx>> { ) -> chalk_ir::VariableKinds<RustInterner<'tcx>> {
chalk_ir::ParameterKinds::from( chalk_ir::VariableKinds::from(
interner, interner,
bound_vars.iter().map(|arg| match arg.unpack() { bound_vars.iter().map(|arg| match arg.unpack() {
ty::subst::GenericArgKind::Lifetime(_re) => chalk_ir::ParameterKind::Lifetime(()), ty::subst::GenericArgKind::Lifetime(_re) => chalk_ir::VariableKind::Lifetime,
ty::subst::GenericArgKind::Type(_ty) => chalk_ir::ParameterKind::Ty(()), ty::subst::GenericArgKind::Type(_ty) => {
ty::subst::GenericArgKind::Const(_const) => chalk_ir::ParameterKind::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::*; use TyKind::*;
let empty = || chalk_ir::Substitution::empty(interner); 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| { let apply = |name, substitution| {
TyData::Apply(chalk_ir::ApplicationTy { name, substitution }).intern(interner) 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), struct_ty(RustDefId::Array),
chalk_ir::Substitution::from1( chalk_ir::Substitution::from1(
interner, interner,
chalk_ir::ParameterKind::Ty(ty.lower_into(interner)).intern(interner), chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
), ),
), ),
Slice(ty) => apply( Slice(ty) => apply(
chalk_ir::TypeName::Slice, chalk_ir::TypeName::Slice,
chalk_ir::Substitution::from1( chalk_ir::Substitution::from1(
interner, interner,
chalk_ir::ParameterKind::Ty(ty.lower_into(interner)).intern(interner), chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
), ),
), ),
RawPtr(ptr) => { RawPtr(ptr) => {
@ -341,9 +341,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
chalk_ir::Substitution::from( chalk_ir::Substitution::from(
interner, interner,
&[ &[
chalk_ir::ParameterKind::Lifetime(region.lower_into(interner)) chalk_ir::GenericArgData::Lifetime(region.lower_into(interner))
.intern(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( substitution: chalk_ir::Substitution::from(
interner, interner,
inputs_and_outputs.iter().map(|ty| { 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> { impl<'tcx> LowerInto<'tcx, chalk_ir::GenericArg<RustInterner<'tcx>>> for GenericArg<'tcx> {
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Parameter<RustInterner<'tcx>> { fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::GenericArg<RustInterner<'tcx>> {
match self.unpack() { match self.unpack() {
ty::subst::GenericArgKind::Type(ty) => { 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) => { 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 { chalk_ir::TyData::Apply(chalk_ir::ApplicationTy {
name: chalk_ir::TypeName::Tuple(0), name: chalk_ir::TypeName::Tuple(0),
substitution: chalk_ir::Substitution::empty(interner), 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 { let where_clauses = predicates.into_iter().map(|predicate| match predicate {
ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef { def_id, substs }) => { ty::ExistentialPredicate::Trait(ty::ExistentialTraitRef { def_id, substs }) => {
chalk_ir::Binders::new( chalk_ir::Binders::new(
chalk_ir::ParameterKinds::new(interner), chalk_ir::VariableKinds::new(interner),
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef { chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
trait_id: chalk_ir::TraitId(RustDefId::Trait(*def_id)), trait_id: chalk_ir::TraitId(RustDefId::Trait(*def_id)),
substitution: substs.lower_into(interner), 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::Projection(_predicate) => unimplemented!(),
ty::ExistentialPredicate::AutoTrait(def_id) => chalk_ir::Binders::new( 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 { chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
trait_id: chalk_ir::TraitId(RustDefId::Trait(*def_id)), trait_id: chalk_ir::TraitId(RustDefId::Trait(*def_id)),
substitution: chalk_ir::Substitution::empty(interner), substitution: chalk_ir::Substitution::empty(interner),
@ -541,7 +541,7 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
interner: &RustInterner<'tcx>, interner: &RustInterner<'tcx>,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
ty: &'a Binder<T>, 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(); let mut bound_vars_collector = BoundVarsCollector::new();
ty.skip_binder().visit_with(&mut bound_vars_collector); ty.skip_binder().visit_with(&mut bound_vars_collector);
let mut parameters = bound_vars_collector.parameters; 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); let new_ty = ty.skip_binder().fold_with(&mut bound_var_substitutor);
for var in named_parameters.values() { 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| { (0..parameters.len()).for_each(|i| {
parameters.get(&(i as u32)).expect("Skipped bound var index."); 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) (new_ty, binders, named_parameters)
} }
crate struct BoundVarsCollector { crate struct BoundVarsCollector<'tcx> {
binder_index: ty::DebruijnIndex, 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>, crate named_parameters: Vec<DefId>,
} }
impl BoundVarsCollector { impl<'tcx> BoundVarsCollector<'tcx> {
crate fn new() -> Self { crate fn new() -> Self {
BoundVarsCollector { BoundVarsCollector {
binder_index: ty::INNERMOST, 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 { fn visit_binder<T: TypeFoldable<'tcx>>(&mut self, t: &Binder<T>) -> bool {
self.binder_index.shift_in(1); self.binder_index.shift_in(1);
let result = t.super_visit_with(self); 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 => { ty::Bound(debruijn, bound_ty) if debruijn == self.binder_index => {
match self.parameters.entry(bound_ty.var.as_u32()) { match self.parameters.entry(bound_ty.var.as_u32()) {
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
entry.insert(chalk_ir::ParameterKind::Ty(())); entry.insert(chalk_ir::VariableKind::Ty(chalk_ir::TyKind::General));
}
Entry::Occupied(entry) => {
entry.get().assert_ty_ref();
} }
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) { ty::BoundRegion::BrAnon(var) => match self.parameters.entry(*var) {
Entry::Vacant(entry) => { Entry::Vacant(entry) => {
entry.insert(chalk_ir::ParameterKind::Lifetime(())); entry.insert(chalk_ir::VariableKind::Lifetime);
}
Entry::Occupied(entry) => {
entry.get().assert_lifetime_ref();
} }
Entry::Occupied(entry) => match entry.get() {
chalk_ir::VariableKind::Lifetime => {}
_ => panic!(),
},
}, },
ty::BrEnv => unimplemented!(), ty::BrEnv => unimplemented!(),

View File

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