mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 04:23:25 +00:00
Upgrade Chalk
This commit is contained in:
parent
c388130f5f
commit
c216a93da7
3 changed files with 88 additions and 22 deletions
25
Cargo.lock
generated
25
Cargo.lock
generated
|
@ -114,17 +114,18 @@ checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
|
|||
[[package]]
|
||||
name = "chalk-derive"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"synstructure",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chalk-engine"
|
||||
version = "0.9.0"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea"
|
||||
dependencies = [
|
||||
"chalk-macros",
|
||||
"rustc-hash",
|
||||
|
@ -133,7 +134,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "chalk-ir"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-engine",
|
||||
|
@ -143,7 +144,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "chalk-macros"
|
||||
version = "0.1.1"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
]
|
||||
|
@ -151,7 +152,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "chalk-rust-ir"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-engine",
|
||||
|
@ -162,7 +163,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "chalk-solve"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=039fc904a05f8cb3d0c682c9a57a63dda7a35356#039fc904a05f8cb3d0c682c9a57a63dda7a35356"
|
||||
source = "git+https://github.com/rust-lang/chalk.git?rev=6222e416b96892b2a86bc08de7dbc9826ff1acea#6222e416b96892b2a86bc08de7dbc9826ff1acea"
|
||||
dependencies = [
|
||||
"chalk-derive",
|
||||
"chalk-engine",
|
||||
|
@ -1564,6 +1565,18 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.12.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67656ea1dc1b41b1451851562ea232ec2e5a80242139f7e679ceccfb5d61f545"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.1.0"
|
||||
|
|
|
@ -26,9 +26,9 @@ test_utils = { path = "../test_utils" }
|
|||
|
||||
scoped-tls = "1"
|
||||
|
||||
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" }
|
||||
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" }
|
||||
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "039fc904a05f8cb3d0c682c9a57a63dda7a35356" }
|
||||
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "6222e416b96892b2a86bc08de7dbc9826ff1acea" }
|
||||
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "6222e416b96892b2a86bc08de7dbc9826ff1acea" }
|
||||
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "6222e416b96892b2a86bc08de7dbc9826ff1acea" }
|
||||
|
||||
[dev-dependencies]
|
||||
insta = "0.15.0"
|
||||
|
|
|
@ -32,6 +32,9 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
type InternedGoal = Arc<GoalData<Self>>;
|
||||
type InternedGoals = Vec<Goal<Self>>;
|
||||
type InternedSubstitution = Vec<Parameter<Self>>;
|
||||
type InternedProgramClause = chalk_ir::ProgramClauseData<Self>;
|
||||
type InternedProgramClauses = Vec<chalk_ir::ProgramClause<Self>>;
|
||||
type InternedQuantifiedWhereClauses = Vec<chalk_ir::QuantifiedWhereClause<Self>>;
|
||||
type Identifier = TypeAliasId;
|
||||
type DefId = InternId;
|
||||
|
||||
|
@ -181,6 +184,48 @@ impl chalk_ir::interner::Interner for Interner {
|
|||
) -> &'a [Parameter<Self>] {
|
||||
substitution
|
||||
}
|
||||
|
||||
fn intern_program_clause(
|
||||
&self,
|
||||
data: chalk_ir::ProgramClauseData<Self>,
|
||||
) -> chalk_ir::ProgramClauseData<Self> {
|
||||
data
|
||||
}
|
||||
|
||||
fn program_clause_data<'a>(
|
||||
&self,
|
||||
clause: &'a chalk_ir::ProgramClauseData<Self>,
|
||||
) -> &'a chalk_ir::ProgramClauseData<Self> {
|
||||
clause
|
||||
}
|
||||
|
||||
fn intern_program_clauses(
|
||||
&self,
|
||||
data: impl IntoIterator<Item = chalk_ir::ProgramClause<Self>>,
|
||||
) -> Vec<chalk_ir::ProgramClause<Self>> {
|
||||
data.into_iter().collect()
|
||||
}
|
||||
|
||||
fn program_clauses_data<'a>(
|
||||
&self,
|
||||
clauses: &'a Vec<chalk_ir::ProgramClause<Self>>,
|
||||
) -> &'a [chalk_ir::ProgramClause<Self>] {
|
||||
clauses
|
||||
}
|
||||
|
||||
fn intern_quantified_where_clauses(
|
||||
&self,
|
||||
data: impl IntoIterator<Item = chalk_ir::QuantifiedWhereClause<Self>>,
|
||||
) -> Self::InternedQuantifiedWhereClauses {
|
||||
data.into_iter().collect()
|
||||
}
|
||||
|
||||
fn quantified_where_clauses_data<'a>(
|
||||
&self,
|
||||
clauses: &'a Self::InternedQuantifiedWhereClauses,
|
||||
) -> &'a [chalk_ir::QuantifiedWhereClause<Self>] {
|
||||
clauses
|
||||
}
|
||||
}
|
||||
|
||||
impl chalk_ir::interner::HasInterner for Interner {
|
||||
|
@ -238,12 +283,10 @@ impl ToChalk for Ty {
|
|||
Ty::Bound(idx) => chalk_ir::TyData::BoundVar(idx).intern(&Interner),
|
||||
Ty::Infer(_infer_ty) => panic!("uncanonicalized infer ty"),
|
||||
Ty::Dyn(predicates) => {
|
||||
let where_clauses = predicates
|
||||
.iter()
|
||||
.filter(|p| !p.is_error())
|
||||
.cloned()
|
||||
.map(|p| p.to_chalk(db))
|
||||
.collect();
|
||||
let where_clauses = chalk_ir::QuantifiedWhereClauses::from(
|
||||
&Interner,
|
||||
predicates.iter().filter(|p| !p.is_error()).cloned().map(|p| p.to_chalk(db)),
|
||||
);
|
||||
let bounded_ty = chalk_ir::DynTy { bounds: make_binders(where_clauses, 1) };
|
||||
chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner)
|
||||
}
|
||||
|
@ -281,8 +324,12 @@ impl ToChalk for Ty {
|
|||
chalk_ir::TyData::InferenceVar(_iv) => Ty::Unknown,
|
||||
chalk_ir::TyData::Dyn(where_clauses) => {
|
||||
assert_eq!(where_clauses.bounds.binders.len(), 1);
|
||||
let predicates =
|
||||
where_clauses.bounds.value.into_iter().map(|c| from_chalk(db, c)).collect();
|
||||
let predicates = where_clauses
|
||||
.bounds
|
||||
.skip_binders()
|
||||
.iter(&Interner)
|
||||
.map(|c| from_chalk(db, c.clone()))
|
||||
.collect();
|
||||
Ty::Dyn(predicates)
|
||||
}
|
||||
}
|
||||
|
@ -426,7 +473,7 @@ impl ToChalk for GenericPredicate {
|
|||
) -> GenericPredicate {
|
||||
// we don't produce any where clauses with binders and can't currently deal with them
|
||||
match where_clause
|
||||
.value
|
||||
.skip_binders()
|
||||
.shifted_out(&Interner)
|
||||
.expect("unexpected bound vars in where clause")
|
||||
{
|
||||
|
@ -521,7 +568,7 @@ impl ToChalk for Arc<super::TraitEnvironment> {
|
|||
pred.clone().to_chalk(db).cast(&Interner);
|
||||
clauses.push(program_clause.into_from_env_clause(&Interner));
|
||||
}
|
||||
chalk_ir::Environment::new().add_clauses(clauses)
|
||||
chalk_ir::Environment::new(&Interner).add_clauses(&Interner, clauses)
|
||||
}
|
||||
|
||||
fn from_chalk(
|
||||
|
@ -603,10 +650,10 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData {
|
|||
}
|
||||
|
||||
fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> {
|
||||
chalk_ir::Binders {
|
||||
chalk_ir::Binders::new(
|
||||
std::iter::repeat(chalk_ir::ParameterKind::Ty(())).take(num_vars).collect(),
|
||||
value,
|
||||
binders: std::iter::repeat(chalk_ir::ParameterKind::Ty(())).take(num_vars).collect(),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fn convert_where_clauses(
|
||||
|
@ -696,6 +743,12 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
|
|||
fn interner(&self) -> &Interner {
|
||||
&Interner
|
||||
}
|
||||
fn well_known_trait_id(
|
||||
&self,
|
||||
_well_known_trait: chalk_rust_ir::WellKnownTrait,
|
||||
) -> chalk_ir::TraitId<Interner> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn associated_ty_data_query(
|
||||
|
|
Loading…
Reference in a new issue