Upgrade chalk to 0.21

This commit is contained in:
Jack Huey 2020-08-04 18:35:37 -04:00
parent 42d896afbd
commit d66452c3e5
11 changed files with 190 additions and 120 deletions

View File

@ -427,9 +427,9 @@ dependencies = [
[[package]]
name = "chalk-derive"
version = "0.14.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d463e01905d607e181de72e8608721d3269f29176c9a14ce037011316ae7131d"
checksum = "c1df0dbb57d74b4acd20f20fa66ab2acd09776b79eaeb9d8f947b2f3e01c40bf"
dependencies = [
"proc-macro2",
"quote",
@ -439,21 +439,22 @@ dependencies = [
[[package]]
name = "chalk-engine"
version = "0.14.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efaf428f5398d36284f79690cf988762b7c091249f50a6c11db613a46c057000"
checksum = "fb7c65a13f32f02aba8f1d9a37f206af615f77ac564624b81a4c593c6c1735b9"
dependencies = [
"chalk-derive",
"chalk-ir",
"chalk-solve",
"rustc-hash",
"tracing",
]
[[package]]
name = "chalk-ir"
version = "0.14.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd3fdc1e9f68498ffe80f4a23b0b95f1ca6fb21d5a4c9b0c085fab3ca712bdbe"
checksum = "44361a25dbdb1dc428f56ad7a3c21ba9ca12f3225c26a47919ff6fcb10a583d4"
dependencies = [
"chalk-derive",
"lazy_static",
@ -461,18 +462,19 @@ dependencies = [
[[package]]
name = "chalk-solve"
version = "0.14.0"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b9fd4102807b7ebe8fb034fa0f488c5656e1966d3261b558b81a08d519cdb29"
checksum = "a886da37a0dc457057d86f78f026f7a09c6d8088aa13f4f4127fdb8dc80119a3"
dependencies = [
"chalk-derive",
"chalk-engine",
"chalk-ir",
"ena",
"itertools 0.9.0",
"petgraph",
"rustc-hash",
"tracing",
"tracing-subscriber",
"tracing-tree",
]
[[package]]
@ -4038,6 +4040,7 @@ dependencies = [
name = "rustc_traits"
version = "0.0.0"
dependencies = [
"chalk-engine",
"chalk-ir",
"chalk-solve",
"rustc_ast",
@ -4996,6 +4999,27 @@ dependencies = [
"lazy_static",
]
[[package]]
name = "tracing-log"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5e0f8c7178e13481ff6765bd169b33e8d554c5d2bbede5e32c356194be02b9b9"
dependencies = [
"lazy_static",
"log",
"tracing-core",
]
[[package]]
name = "tracing-serde"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6ccba2f8f16e0ed268fc765d9b7ff22e965e7185d32f8f1ec8294fe17d86e79"
dependencies = [
"serde",
"tracing-core",
]
[[package]]
name = "tracing-subscriber"
version = "0.2.11"
@ -5003,14 +5027,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abd165311cc4d7a555ad11cc77a37756df836182db0d81aac908c8184c584f40"
dependencies = [
"ansi_term 0.12.1",
"chrono",
"lazy_static",
"matchers",
"parking_lot 0.11.0",
"regex",
"serde",
"serde_json",
"sharded-slab",
"smallvec 1.4.2",
"thread_local",
"tracing-core",
"tracing-log",
"tracing-serde",
]
[[package]]
name = "tracing-tree"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1a3dc4774db3a6b2d66a4f8d8de670e874ec3ed55615860c994927419b32c5f"
dependencies = [
"ansi_term 0.12.1",
"atty",
"chrono",
"termcolor",
"tracing",
"tracing-subscriber",
]
[[package]]

View File

@ -27,7 +27,7 @@ rustc_serialize = { path = "../rustc_serialize" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
byteorder = { version = "1.3" }
chalk-ir = "0.14.0"
chalk-ir = "0.21.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
measureme = "0.7.1"
rustc_session = { path = "../rustc_session" }

View File

@ -75,6 +75,7 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
type InternedVariableKinds = Vec<chalk_ir::VariableKind<Self>>;
type InternedCanonicalVarKinds = Vec<chalk_ir::CanonicalVarKind<Self>>;
type InternedConstraints = Vec<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>>;
type DefId = DefId;
type InternedAdtId = &'tcx AdtDef;
type Identifier = ();
@ -321,6 +322,20 @@ impl<'tcx> chalk_ir::interner::Interner for RustInterner<'tcx> {
) -> &'a [chalk_ir::CanonicalVarKind<Self>] {
canonical_var_kinds
}
fn intern_constraints<E>(
&self,
data: impl IntoIterator<Item = Result<chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>, E>>,
) -> Result<Self::InternedConstraints, E> {
data.into_iter().collect::<Result<Vec<_>, _>>()
}
fn constraints_data<'a>(
&self,
constraints: &'a Self::InternedConstraints,
) -> &'a [chalk_ir::InEnvironment<chalk_ir::Constraint<Self>>] {
constraints
}
}
impl<'tcx> chalk_ir::interner::HasInterner for RustInterner<'tcx> {

View File

@ -12,8 +12,9 @@ rustc_hir = { path = "../rustc_hir" }
rustc_index = { path = "../rustc_index" }
rustc_ast = { path = "../rustc_ast" }
rustc_span = { path = "../rustc_span" }
chalk-ir = "0.14.0"
chalk-solve = "0.14.0"
chalk-ir = "0.21.0"
chalk-solve = "0.21.0"
chalk-engine = "0.21.0"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
rustc_infer = { path = "../rustc_infer" }
rustc_trait_selection = { path = "../rustc_trait_selection" }

View File

@ -11,6 +11,7 @@ use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
use rustc_middle::ty::{self, AssocItemContainer, AssocKind, TyCtxt};
use rustc_hir::def_id::DefId;
use rustc_hir::Unsafety;
use rustc_span::symbol::sym;
@ -145,10 +146,11 @@ 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 fields = match adt_def.adt_kind() {
ty::AdtKind::Struct | ty::AdtKind::Union => {
let variant = adt_def.non_enum_variant();
variant
let variants: Vec<_> = adt_def
.variants
.iter()
.map(|variant| chalk_solve::rust_ir::AdtVariantDatum {
fields: variant
.fields
.iter()
.map(|field| {
@ -157,26 +159,40 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
.subst(self.tcx, bound_vars)
.lower_into(&self.interner)
})
.collect()
}
// FIXME(chalk): handle enums; force_impl_for requires this
ty::AdtKind::Enum => vec![],
};
.collect(),
})
.collect();
let struct_datum = Arc::new(chalk_solve::rust_ir::AdtDatum {
id: adt_id,
binders: chalk_ir::Binders::new(
binders,
chalk_solve::rust_ir::AdtDatumBound { fields, where_clauses },
chalk_solve::rust_ir::AdtDatumBound { variants, where_clauses },
),
flags: chalk_solve::rust_ir::AdtFlags {
upstream: !adt_def.did.is_local(),
fundamental: adt_def.is_fundamental(),
phantom_data: adt_def.is_phantom_data(),
},
kind: match adt_def.adt_kind() {
ty::AdtKind::Struct => chalk_solve::rust_ir::AdtKind::Struct,
ty::AdtKind::Union => chalk_solve::rust_ir::AdtKind::Union,
ty::AdtKind::Enum => chalk_solve::rust_ir::AdtKind::Enum,
},
});
struct_datum
}
fn adt_repr(
&self,
adt_id: chalk_ir::AdtId<RustInterner<'tcx>>,
) -> chalk_solve::rust_ir::AdtRepr {
let adt_def = adt_id.0;
chalk_solve::rust_ir::AdtRepr {
repr_c: adt_def.repr.c(),
repr_packed: adt_def.repr.packed(),
}
}
fn fn_def_datum(
&self,
fn_def_id: chalk_ir::FnDefId<RustInterner<'tcx>>,
@ -218,6 +234,11 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
Arc::new(chalk_solve::rust_ir::FnDefDatum {
id: fn_def_id,
abi: sig.abi(),
safety: match sig.unsafety() {
Unsafety::Normal => chalk_ir::Safety::Safe,
Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
},
variadic: sig.c_variadic(),
binders: chalk_ir::Binders::new(binders, bound),
})
}
@ -256,6 +277,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
&self,
trait_id: chalk_ir::TraitId<RustInterner<'tcx>>,
parameters: &[chalk_ir::GenericArg<RustInterner<'tcx>>],
_binders: &chalk_ir::CanonicalVarKinds<RustInterner<'tcx>>,
) -> Vec<chalk_ir::ImplId<RustInterner<'tcx>>> {
let def_id = trait_id.0;
@ -355,69 +377,15 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
.filter_map(|wc| LowerInto::<Option<chalk_ir::QuantifiedWhereClause<RustInterner<'tcx>>>>::lower_into(wc, &self.interner)).collect();
let value = chalk_solve::rust_ir::OpaqueTyDatumBound {
bounds: chalk_ir::Binders::new(binders, where_clauses),
bounds: chalk_ir::Binders::new(binders.clone(), vec![]),
where_clauses: chalk_ir::Binders::new(binders, where_clauses),
};
Arc::new(chalk_solve::rust_ir::OpaqueTyDatum {
opaque_ty_id,
bound: chalk_ir::Binders::new(chalk_ir::VariableKinds::new(&self.interner), value),
bound: chalk_ir::Binders::new(chalk_ir::VariableKinds::empty(&self.interner), value),
})
}
/// Since Chalk can't handle all Rust types currently, we have to handle
/// some specially for now. Over time, these `Some` returns will change to
/// `None` and eventually this function will be removed.
fn force_impl_for(
&self,
well_known: chalk_solve::rust_ir::WellKnownTrait,
ty: &chalk_ir::TyData<RustInterner<'tcx>>,
) -> Option<bool> {
use chalk_ir::TyData::*;
match well_known {
chalk_solve::rust_ir::WellKnownTrait::Sized => match ty {
Apply(apply) => match apply.name {
chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def)) => match adt_def.adt_kind() {
ty::AdtKind::Struct | ty::AdtKind::Union => None,
ty::AdtKind::Enum => {
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
if !constraint.0.is_empty() { unimplemented!() } else { Some(true) }
}
},
_ => None,
},
Dyn(_)
| Alias(_)
| Placeholder(_)
| Function(_)
| InferenceVar(_, _)
| BoundVar(_) => None,
},
chalk_solve::rust_ir::WellKnownTrait::Copy
| chalk_solve::rust_ir::WellKnownTrait::Clone => match ty {
Apply(apply) => match apply.name {
chalk_ir::TypeName::Adt(chalk_ir::AdtId(adt_def)) => match adt_def.adt_kind() {
ty::AdtKind::Struct | ty::AdtKind::Union => None,
ty::AdtKind::Enum => {
let constraint = self.tcx.adt_sized_constraint(adt_def.did);
if !constraint.0.is_empty() { unimplemented!() } else { Some(true) }
}
},
_ => None,
},
Dyn(_)
| Alias(_)
| Placeholder(_)
| Function(_)
| InferenceVar(_, _)
| BoundVar(_) => None,
},
chalk_solve::rust_ir::WellKnownTrait::Drop => None,
chalk_solve::rust_ir::WellKnownTrait::Fn => None,
chalk_solve::rust_ir::WellKnownTrait::FnMut => None,
chalk_solve::rust_ir::WellKnownTrait::FnOnce => None,
chalk_solve::rust_ir::WellKnownTrait::Unsize => None,
}
}
fn program_clauses_for_env(
&self,
environment: &chalk_ir::Environment<RustInterner<'tcx>>,
@ -460,7 +428,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
_closure_id: chalk_ir::ClosureId<RustInterner<'tcx>>,
substs: &chalk_ir::Substitution<RustInterner<'tcx>>,
) -> chalk_solve::rust_ir::ClosureKind {
let kind = &substs.parameters(&self.interner)[substs.len(&self.interner) - 3];
let kind = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 3];
match kind.assert_ty_ref(&self.interner).data(&self.interner) {
chalk_ir::TyData::Apply(apply) => match apply.name {
chalk_ir::TypeName::Scalar(scalar) => match scalar {
@ -484,10 +452,10 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
substs: &chalk_ir::Substitution<RustInterner<'tcx>>,
) -> chalk_ir::Binders<chalk_solve::rust_ir::FnDefInputsAndOutputDatum<RustInterner<'tcx>>>
{
let sig = &substs.parameters(&self.interner)[substs.len(&self.interner) - 2];
let sig = &substs.as_slice(&self.interner)[substs.len(&self.interner) - 2];
match sig.assert_ty_ref(&self.interner).data(&self.interner) {
chalk_ir::TyData::Function(f) => {
let substitution = f.substitution.parameters(&self.interner);
let substitution = f.substitution.as_slice(&self.interner);
let return_type =
substitution.last().unwrap().assert_ty_ref(&self.interner).clone();
// Closure arguments are tupled
@ -506,7 +474,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
};
chalk_ir::Binders::new(
chalk_ir::VariableKinds::from(
chalk_ir::VariableKinds::from_iter(
&self.interner,
(0..f.num_binders).map(|_| chalk_ir::VariableKind::Lifetime),
),
@ -523,7 +491,7 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
substs: &chalk_ir::Substitution<RustInterner<'tcx>>,
) -> chalk_ir::Binders<chalk_ir::Ty<RustInterner<'tcx>>> {
let inputs_and_output = self.closure_inputs_and_output(_closure_id, substs);
let tuple = substs.parameters(&self.interner).last().unwrap().assert_ty_ref(&self.interner);
let tuple = substs.as_slice(&self.interner).last().unwrap().assert_ty_ref(&self.interner);
inputs_and_output.map_ref(|_| tuple.clone())
}
@ -532,8 +500,8 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
_closure_id: chalk_ir::ClosureId<RustInterner<'tcx>>,
substs: &chalk_ir::Substitution<RustInterner<'tcx>>,
) -> chalk_ir::Substitution<RustInterner<'tcx>> {
let substitution = &substs.parameters(&self.interner)[0..substs.len(&self.interner) - 3];
chalk_ir::Substitution::from(&self.interner, substitution)
let substitution = &substs.as_slice(&self.interner)[0..substs.len(&self.interner) - 3];
chalk_ir::Substitution::from_iter(&self.interner, substitution)
}
}
@ -573,7 +541,7 @@ fn binders_for<'tcx>(
interner: &RustInterner<'tcx>,
bound_vars: SubstsRef<'tcx>,
) -> chalk_ir::VariableKinds<RustInterner<'tcx>> {
chalk_ir::VariableKinds::from(
chalk_ir::VariableKinds::from_iter(
interner,
bound_vars.iter().map(|arg| match arg.unpack() {
ty::subst::GenericArgKind::Lifetime(_re) => chalk_ir::VariableKind::Lifetime,

View File

@ -56,7 +56,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Substitution<RustInterner<'tcx>>> for Subst
self,
interner: &RustInterner<'tcx>,
) -> chalk_ir::Substitution<RustInterner<'tcx>> {
chalk_ir::Substitution::from(interner, self.iter().map(|s| s.lower_into(interner)))
chalk_ir::Substitution::from_iter(interner, self.iter().map(|s| s.lower_into(interner)))
}
}
@ -94,8 +94,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
predicate.trait_ref.lower_into(interner),
),
),
conditions: chalk_ir::Goals::new(interner),
conditions: chalk_ir::Goals::empty(interner),
priority: chalk_ir::ClausePriority::High,
constraints: chalk_ir::Constraints::empty(interner),
},
))
.intern(interner),
@ -118,15 +119,39 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
},
),
),
conditions: chalk_ir::Goals::new(interner),
conditions: chalk_ir::Goals::empty(interner),
priority: chalk_ir::ClausePriority::High,
constraints: chalk_ir::Constraints::empty(interner),
},
))
.intern(interner),
)
}
ty::PredicateAtom::TypeOutlives(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &predicate);
Some(
chalk_ir::ProgramClauseData(chalk_ir::Binders::new(
binders,
chalk_ir::ProgramClauseImplication {
consequence: chalk_ir::DomainGoal::Holds(
chalk_ir::WhereClause::TypeOutlives(
chalk_ir::TypeOutlives {
ty: predicate.0.lower_into(interner),
lifetime: predicate.1.lower_into(interner),
},
),
),
conditions: chalk_ir::Goals::empty(interner),
priority: chalk_ir::ClausePriority::High,
constraints: chalk_ir::Constraints::empty(interner),
},
))
.intern(interner),
)
}
// FIXME(chalk): need to add TypeOutlives
ty::PredicateAtom::TypeOutlives(_) => None,
ty::PredicateAtom::Projection(predicate) => {
let predicate = ty::Binder::bind(predicate);
let (predicate, binders, _named_regions) =
@ -141,8 +166,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
predicate.lower_into(interner),
),
),
conditions: chalk_ir::Goals::new(interner),
conditions: chalk_ir::Goals::empty(interner),
priority: chalk_ir::ClausePriority::High,
constraints: chalk_ir::Constraints::empty(interner),
},
))
.intern(interner),
@ -160,13 +186,14 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
}
ChalkEnvironmentClause::TypeFromEnv(ty) => Some(
chalk_ir::ProgramClauseData(chalk_ir::Binders::new(
chalk_ir::VariableKinds::new(interner),
chalk_ir::VariableKinds::empty(interner),
chalk_ir::ProgramClauseImplication {
consequence: chalk_ir::DomainGoal::FromEnv(chalk_ir::FromEnv::Ty(
ty.lower_into(interner).shifted_in(interner),
)),
conditions: chalk_ir::Goals::new(interner),
conditions: chalk_ir::Goals::empty(interner),
priority: chalk_ir::ClausePriority::High,
constraints: chalk_ir::Constraints::empty(interner),
},
))
.intern(interner),
@ -176,7 +203,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::InEnvironment<chalk_ir::Goal<RustInterner<'
let goal: chalk_ir::GoalData<RustInterner<'tcx>> = self.goal.lower_into(&interner);
chalk_ir::InEnvironment {
environment: chalk_ir::Environment {
clauses: chalk_ir::ProgramClauses::from(&interner, clauses),
clauses: chalk_ir::ProgramClauses::from_iter(&interner, clauses),
},
goal: goal.intern(&interner),
}
@ -211,7 +238,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
}
// FIXME(chalk): TypeOutlives
ty::PredicateAtom::TypeOutlives(_predicate) => {
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
ty::PredicateAtom::Projection(predicate) => {
ty::Binder::bind(predicate).lower_into(interner)
@ -221,7 +248,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
// FIXME(chalk): In Chalk, a placeholder is WellFormed if it
// `FromEnv`. However, when we "lower" Params, we don't update
// the environment.
ty::Placeholder(..) => chalk_ir::GoalData::All(chalk_ir::Goals::new(interner)),
ty::Placeholder(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
_ => {
let (ty, binders, _named_regions) =
@ -241,7 +270,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
},
// FIXME(chalk): handle well formed consts
GenericArgKind::Const(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
GenericArgKind::Lifetime(lt) => bug!("unexpect well formed predicate: {:?}", lt),
},
@ -258,7 +287,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::GoalData<RustInterner<'tcx>>> for ty::Predi
| ty::PredicateAtom::Subtype(..)
| ty::PredicateAtom::ConstEvaluatable(..)
| ty::PredicateAtom::ConstEquate(..) => {
chalk_ir::GoalData::All(chalk_ir::Goals::new(interner))
chalk_ir::GoalData::All(chalk_ir::Goals::empty(interner))
}
}
}
@ -381,7 +410,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
};
apply(
chalk_ir::TypeName::Array,
chalk_ir::Substitution::from(
chalk_ir::Substitution::from_iter(
interner,
&[
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner),
@ -415,7 +444,7 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
};
apply(
name,
chalk_ir::Substitution::from(
chalk_ir::Substitution::from_iter(
interner,
&[
chalk_ir::GenericArgData::Lifetime(region.lower_into(interner))
@ -432,14 +461,20 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
FnPtr(sig) => {
let (inputs_and_outputs, binders, _named_regions) =
collect_bound_vars(interner, interner.tcx, &sig.inputs_and_output());
TyData::Function(chalk_ir::Fn {
TyData::Function(chalk_ir::FnPointer {
num_binders: binders.len(interner),
substitution: chalk_ir::Substitution::from(
substitution: chalk_ir::Substitution::from_iter(
interner,
inputs_and_outputs.iter().map(|ty| {
chalk_ir::GenericArgData::Ty(ty.lower_into(interner)).intern(interner)
}),
),
abi: sig.abi(),
safety: match sig.unsafety() {
rustc_hir::Unsafety::Normal => chalk_ir::Safety::Safe,
rustc_hir::Unsafety::Unsafe => chalk_ir::Safety::Unsafe,
},
variadic: sig.c_variadic(),
})
.intern(interner)
}
@ -604,7 +639,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::VariableKinds::new(interner),
chalk_ir::VariableKinds::empty(interner),
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
trait_id: chalk_ir::TraitId(def_id),
substitution: substs.lower_into(interner),
@ -613,14 +648,14 @@ 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::VariableKinds::new(interner),
chalk_ir::VariableKinds::empty(interner),
chalk_ir::WhereClause::Implemented(chalk_ir::TraitRef {
trait_id: chalk_ir::TraitId(def_id),
substitution: chalk_ir::Substitution::empty(interner),
}),
),
});
let value = chalk_ir::QuantifiedWhereClauses::from(interner, where_clauses);
let value = chalk_ir::QuantifiedWhereClauses::from_iter(interner, where_clauses);
chalk_ir::Binders::new(binders, value)
}
}
@ -662,7 +697,8 @@ crate fn collect_bound_vars<'a, 'tcx, T: TypeFoldable<'tcx>>(
.or_else(|| bug!("Skipped bound var index: ty={:?}, parameters={:?}", ty, parameters));
});
let binders = chalk_ir::VariableKinds::from(interner, parameters.into_iter().map(|(_, v)| v));
let binders =
chalk_ir::VariableKinds::from_iter(interner, parameters.into_iter().map(|(_, v)| v));
(new_ty, binders, named_parameters)
}

View File

@ -49,7 +49,7 @@ crate fn evaluate_goal<'tcx>(
chalk_ir::InEnvironment<chalk_ir::Goal<ChalkRustInterner<'tcx>>>,
> = chalk_ir::UCanonical {
canonical: chalk_ir::Canonical {
binders: chalk_ir::CanonicalVarKinds::from(
binders: chalk_ir::CanonicalVarKinds::from_iter(
&interner,
obligation.variables.iter().map(|v| match v.kind {
CanonicalVarKind::PlaceholderTy(_ty) => unimplemented!(),
@ -81,11 +81,10 @@ crate fn evaluate_goal<'tcx>(
universes: max_universe + 1,
};
let solver_choice = chalk_solve::SolverChoice::SLG { max_size: 32, expected_answers: None };
let mut solver = solver_choice.into_solver::<ChalkRustInterner<'tcx>>();
use chalk_solve::Solver;
let mut solver = chalk_engine::solve::SLGSolver::new(32, None);
let db = ChalkRustIrDatabase { tcx, interner };
let solution = solver.solve(&db, &_lowered_goal);
let solution = chalk_solve::logging::with_tracing_logs(|| solver.solve(&db, &_lowered_goal));
// Ideally, the code to convert *back* to rustc types would live close to
// the code to convert *from* rustc types. Right now though, we don't
@ -94,7 +93,7 @@ crate fn evaluate_goal<'tcx>(
// `Ambig(Definite)`. This really isn't right.
let make_solution = |_subst: chalk_ir::Substitution<_>| {
let mut var_values: IndexVec<BoundVar, GenericArg<'tcx>> = IndexVec::new();
_subst.parameters(&interner).iter().for_each(|p| {
_subst.as_slice(&interner).iter().for_each(|p| {
// FIXME(chalk): we should move this elsewhere, since this is
// essentially inverse of lowering a `GenericArg`.
let _data = p.data(&interner);

View File

@ -24,5 +24,5 @@ fn main() {
// Here we have two solutions so we get back the behavior of the old-style
// trait solver.
only_bar(x); //~ ERROR the trait bound `f64: Bar` is not satisfied
only_bar(x); //~ ERROR the trait bound `{float}: Bar` is not satisfied
}

View File

@ -1,11 +1,15 @@
error[E0277]: the trait bound `f64: Bar` is not satisfied
error[E0277]: the trait bound `{float}: Bar` is not satisfied
--> $DIR/type_inference.rs:27:5
|
LL | fn only_bar<T: Bar>(_x: T) { }
| --- required by this bound in `only_bar`
...
LL | only_bar(x);
| ^^^^^^^^ the trait `Bar` is not implemented for `f64`
| ^^^^^^^^ the trait `Bar` is not implemented for `{float}`
|
= help: the following implementations were found:
<i32 as Bar>
<u32 as Bar>
error: aborting due to previous error

View File

@ -15,7 +15,7 @@ fn main() {
x: 5,
};
let s = S { //~ ERROR the trait bound `f64: Foo` is not satisfied
let s = S { //~ ERROR the trait bound `{float}: Foo` is not satisfied
x: 5.0,
};

View File

@ -1,11 +1,15 @@
error[E0277]: the trait bound `f64: Foo` is not satisfied
error[E0277]: the trait bound `{float}: Foo` is not satisfied
--> $DIR/type_wf.rs:18:13
|
LL | struct S<T: Foo> {
| ---------------- required by `S`
...
LL | let s = S {
| ^ the trait `Foo` is not implemented for `f64`
| ^ the trait `Foo` is not implemented for `{float}`
|
= help: the following implementations were found:
<i32 as Foo>
<std::option::Option<T> as Foo>
error: aborting due to previous error