Skip to content

Commit 0f3a598

Browse files
committed
Upgrade Chalk
1 parent 75f6ab2 commit 0f3a598

File tree

4 files changed

+118
-52
lines changed

4 files changed

+118
-52
lines changed

Cargo.lock

Lines changed: 13 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/ra_hir_ty/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ ra_prof = { path = "../ra_prof" }
2121
ra_syntax = { path = "../ra_syntax" }
2222
test_utils = { path = "../test_utils" }
2323

24-
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" }
25-
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" }
26-
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "177d71340acc7a7204a33115fc63075d86452179" }
24+
chalk-solve = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" }
25+
chalk-rust-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" }
26+
chalk-ir = { git = "https://github.com/rust-lang/chalk.git", rev = "d383af7333cc6014e9d9e3e77668b5d5b0a5b40e" }
2727

2828
[dev-dependencies]
2929
insta = "0.15.0"

crates/ra_hir_ty/src/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ pub(crate) fn trait_solve_query(
153153
}
154154
}
155155

156-
let canonical = goal.to_chalk(db).cast();
156+
let canonical = goal.to_chalk(db).cast(&Interner);
157157

158158
// We currently don't deal with universes (I think / hope they're not yet
159159
// relevant for our use cases?)
@@ -194,8 +194,8 @@ fn solution_from_chalk(
194194
let convert_subst = |subst: chalk_ir::Canonical<chalk_ir::Substitution<Interner>>| {
195195
let value = subst
196196
.value
197-
.into_iter()
198-
.map(|p| match p.ty() {
197+
.iter(&Interner)
198+
.map(|p| match p.ty(&Interner) {
199199
Some(ty) => from_chalk(db, ty.clone()),
200200
None => unimplemented!(),
201201
})

crates/ra_hir_ty/src/traits/chalk.rs

Lines changed: 99 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -59,53 +59,126 @@ impl chalk_ir::interner::Interner for Interner {
5959
None
6060
}
6161

62+
fn debug_ty(_ty: &chalk_ir::Ty<Self>, _fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
63+
None
64+
}
65+
66+
fn debug_lifetime(
67+
_lifetime: &chalk_ir::Lifetime<Self>,
68+
_fmt: &mut fmt::Formatter<'_>,
69+
) -> Option<fmt::Result> {
70+
None
71+
}
72+
73+
fn debug_parameter(
74+
_parameter: &Parameter<Self>,
75+
_fmt: &mut fmt::Formatter<'_>,
76+
) -> Option<fmt::Result> {
77+
None
78+
}
79+
80+
fn debug_goal(_goal: &Goal<Self>, _fmt: &mut fmt::Formatter<'_>) -> Option<fmt::Result> {
81+
None
82+
}
83+
84+
fn debug_goals(
85+
_goals: &chalk_ir::Goals<Self>,
86+
_fmt: &mut fmt::Formatter<'_>,
87+
) -> Option<fmt::Result> {
88+
None
89+
}
90+
91+
fn debug_program_clause_implication(
92+
_pci: &chalk_ir::ProgramClauseImplication<Self>,
93+
_fmt: &mut fmt::Formatter<'_>,
94+
) -> Option<fmt::Result> {
95+
None
96+
}
97+
98+
fn debug_application_ty(
99+
_application_ty: &chalk_ir::ApplicationTy<Self>,
100+
_fmt: &mut fmt::Formatter<'_>,
101+
) -> Option<fmt::Result> {
102+
None
103+
}
104+
105+
fn debug_substitution(
106+
_substitution: &chalk_ir::Substitution<Self>,
107+
_fmt: &mut fmt::Formatter<'_>,
108+
) -> Option<fmt::Result> {
109+
None
110+
}
111+
112+
fn debug_separator_trait_ref(
113+
_separator_trait_ref: &chalk_ir::SeparatorTraitRef<Self>,
114+
_fmt: &mut fmt::Formatter<'_>,
115+
) -> Option<fmt::Result> {
116+
None
117+
}
118+
62119
fn intern_ty(&self, ty: chalk_ir::TyData<Self>) -> Box<chalk_ir::TyData<Self>> {
63120
Box::new(ty)
64121
}
65122

66-
fn ty_data(ty: &Box<chalk_ir::TyData<Self>>) -> &chalk_ir::TyData<Self> {
123+
fn ty_data<'a>(&self, ty: &'a Box<chalk_ir::TyData<Self>>) -> &'a chalk_ir::TyData<Self> {
67124
ty
68125
}
69126

70-
fn intern_lifetime(lifetime: chalk_ir::LifetimeData<Self>) -> chalk_ir::LifetimeData<Self> {
127+
fn intern_lifetime(
128+
&self,
129+
lifetime: chalk_ir::LifetimeData<Self>,
130+
) -> chalk_ir::LifetimeData<Self> {
71131
lifetime
72132
}
73133

74-
fn lifetime_data(lifetime: &chalk_ir::LifetimeData<Self>) -> &chalk_ir::LifetimeData<Self> {
134+
fn lifetime_data<'a>(
135+
&self,
136+
lifetime: &'a chalk_ir::LifetimeData<Self>,
137+
) -> &'a chalk_ir::LifetimeData<Self> {
75138
lifetime
76139
}
77140

78-
fn intern_parameter(parameter: chalk_ir::ParameterData<Self>) -> chalk_ir::ParameterData<Self> {
141+
fn intern_parameter(
142+
&self,
143+
parameter: chalk_ir::ParameterData<Self>,
144+
) -> chalk_ir::ParameterData<Self> {
79145
parameter
80146
}
81147

82-
fn parameter_data(parameter: &chalk_ir::ParameterData<Self>) -> &chalk_ir::ParameterData<Self> {
148+
fn parameter_data<'a>(
149+
&self,
150+
parameter: &'a chalk_ir::ParameterData<Self>,
151+
) -> &'a chalk_ir::ParameterData<Self> {
83152
parameter
84153
}
85154

86-
fn intern_goal(goal: GoalData<Self>) -> Arc<GoalData<Self>> {
155+
fn intern_goal(&self, goal: GoalData<Self>) -> Arc<GoalData<Self>> {
87156
Arc::new(goal)
88157
}
89158

90-
fn intern_goals(data: impl IntoIterator<Item = Goal<Self>>) -> Self::InternedGoals {
159+
fn intern_goals(&self, data: impl IntoIterator<Item = Goal<Self>>) -> Self::InternedGoals {
91160
data.into_iter().collect()
92161
}
93162

94-
fn goal_data(goal: &Arc<GoalData<Self>>) -> &GoalData<Self> {
163+
fn goal_data<'a>(&self, goal: &'a Arc<GoalData<Self>>) -> &'a GoalData<Self> {
95164
goal
96165
}
97166

98-
fn goals_data(goals: &Vec<Goal<Interner>>) -> &[Goal<Interner>] {
167+
fn goals_data<'a>(&self, goals: &'a Vec<Goal<Interner>>) -> &'a [Goal<Interner>] {
99168
goals
100169
}
101170

102171
fn intern_substitution<E>(
172+
&self,
103173
data: impl IntoIterator<Item = Result<Parameter<Self>, E>>,
104174
) -> Result<Vec<Parameter<Self>>, E> {
105175
data.into_iter().collect()
106176
}
107177

108-
fn substitution_data(substitution: &Vec<Parameter<Self>>) -> &[Parameter<Self>] {
178+
fn substitution_data<'a>(
179+
&self,
180+
substitution: &'a Vec<Parameter<Self>>,
181+
) -> &'a [Parameter<Self>] {
109182
substitution
110183
}
111184
}
@@ -145,12 +218,14 @@ impl ToChalk for Ty {
145218
Ty::Apply(apply_ty) => {
146219
let name = apply_ty.ctor.to_chalk(db);
147220
let substitution = apply_ty.parameters.to_chalk(db);
148-
chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner)
221+
chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner)
149222
}
150223
Ty::Projection(proj_ty) => {
151224
let associated_ty_id = proj_ty.associated_ty.to_chalk(db);
152225
let substitution = proj_ty.parameters.to_chalk(db);
153-
chalk_ir::AliasTy { associated_ty_id, substitution }.cast().intern(&Interner)
226+
chalk_ir::AliasTy { associated_ty_id, substitution }
227+
.cast(&Interner)
228+
.intern(&Interner)
154229
}
155230
Ty::Placeholder(id) => {
156231
let interned_id = db.intern_type_param_id(id);
@@ -173,14 +248,14 @@ impl ToChalk for Ty {
173248
chalk_ir::TyData::Dyn(bounded_ty).intern(&Interner)
174249
}
175250
Ty::Opaque(_) | Ty::Unknown => {
176-
let substitution = chalk_ir::Substitution::empty();
251+
let substitution = chalk_ir::Substitution::empty(&Interner);
177252
let name = TypeName::Error;
178-
chalk_ir::ApplicationTy { name, substitution }.cast().intern(&Interner)
253+
chalk_ir::ApplicationTy { name, substitution }.cast(&Interner).intern(&Interner)
179254
}
180255
}
181256
}
182257
fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty<Interner>) -> Self {
183-
match chalk.data().clone() {
258+
match chalk.data(&Interner).clone() {
184259
chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name {
185260
TypeName::Error => Ty::Unknown,
186261
_ => {
@@ -218,13 +293,13 @@ impl ToChalk for Substs {
218293
type Chalk = chalk_ir::Substitution<Interner>;
219294

220295
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution<Interner> {
221-
chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db)))
296+
chalk_ir::Substitution::from(&Interner, self.iter().map(|ty| ty.clone().to_chalk(db)))
222297
}
223298

224299
fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution<Interner>) -> Substs {
225300
let tys = parameters
226-
.into_iter()
227-
.map(|p| match p.ty() {
301+
.iter(&Interner)
302+
.map(|p| match p.ty(&Interner) {
228303
Some(ty) => from_chalk(db, ty.clone()),
229304
None => unimplemented!(),
230305
})
@@ -400,8 +475,8 @@ impl ToChalk for Obligation {
400475

401476
fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal<Interner> {
402477
match self {
403-
Obligation::Trait(tr) => tr.to_chalk(db).cast(),
404-
Obligation::Projection(pr) => pr.to_chalk(db).cast(),
478+
Obligation::Trait(tr) => tr.to_chalk(db).cast(&Interner),
479+
Obligation::Projection(pr) => pr.to_chalk(db).cast(&Interner),
405480
}
406481
}
407482

@@ -438,8 +513,8 @@ impl ToChalk for Arc<super::TraitEnvironment> {
438513
continue;
439514
}
440515
let program_clause: chalk_ir::ProgramClause<Interner> =
441-
pred.clone().to_chalk(db).cast();
442-
clauses.push(program_clause.into_from_env_clause());
516+
pred.clone().to_chalk(db).cast(&Interner);
517+
clauses.push(program_clause.into_from_env_clause(&Interner));
443518
}
444519
chalk_ir::Environment::new().add_clauses(clauses)
445520
}
@@ -578,9 +653,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
578653
.map(|impl_| impl_.to_chalk(self.db))
579654
.collect();
580655

581-
let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref().clone());
656+
let ty: Ty = from_chalk(self.db, parameters[0].assert_ty_ref(&Interner).clone());
582657
let arg: Option<Ty> =
583-
parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref().clone()));
658+
parameters.get(1).map(|p| from_chalk(self.db, p.assert_ty_ref(&Interner).clone()));
584659

585660
builtin::get_builtin_impls(self.db, self.krate, &ty, &arg, trait_, |i| {
586661
result.push(i.to_chalk(self.db))

0 commit comments

Comments
 (0)