Skip to content

Commit 76fd010

Browse files
committed
Convert from IndexSet to Vec in lowering
1 parent 5300364 commit 76fd010

File tree

3 files changed

+62
-25
lines changed

3 files changed

+62
-25
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

chalk-integration/src/lowering.rs

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use chalk_ir::{
99
use chalk_parse::ast::*;
1010
use chalk_solve::rust_ir::{self, IntoWhereClauses};
1111
use indexmap::IndexMap;
12+
use indexmap::IndexSet;
1213
use program_lowerer::ProgramLowerer;
1314
use string_cache::DefaultAtom as Atom;
1415
use tracing::debug;
@@ -53,7 +54,7 @@ impl Lower for Program {
5354
trait LowerParameterMap {
5455
fn synthetic_parameters(&self) -> Option<chalk_ir::WithKind<ChalkIr, Ident>>;
5556
fn declared_parameters(&self) -> &[VariableKind];
56-
fn all_parameters(&self) -> Vec<chalk_ir::WithKind<ChalkIr, Ident>> {
57+
fn all_parameters(&self) -> indexmap::IndexSet<chalk_ir::WithKind<ChalkIr, Ident>> {
5758
self.synthetic_parameters()
5859
.into_iter()
5960
.chain(self.declared_parameters().iter().map(|id| id.lower()))
@@ -136,7 +137,7 @@ impl Lower for VariableKind {
136137
}
137138

138139
impl LowerWithEnv for [QuantifiedWhereClause] {
139-
type Lowered = Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
140+
type Lowered = IndexSet<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
140141

141142
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
142143
self.iter()
@@ -149,7 +150,7 @@ impl LowerWithEnv for [QuantifiedWhereClause] {
149150
}
150151

151152
impl LowerWithEnv for WhereClause {
152-
type Lowered = Vec<chalk_ir::WhereClause<ChalkIr>>;
153+
type Lowered = IndexSet<chalk_ir::WhereClause<ChalkIr>>;
153154

154155
/// Lower from an AST `where` clause to an internal IR.
155156
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -158,37 +159,47 @@ impl LowerWithEnv for WhereClause {
158159
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
159160
Ok(match self {
160161
WhereClause::Implemented { trait_ref } => {
161-
vec![chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?)]
162+
let mut set = IndexSet::new();
163+
set.insert(chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?));
164+
set
162165
}
163-
WhereClause::ProjectionEq { projection, ty } => vec![
164-
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
166+
WhereClause::ProjectionEq { projection, ty } => {
167+
let mut set = IndexSet::new();
168+
set.insert(chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
165169
alias: chalk_ir::AliasTy::Projection(projection.lower(env)?),
166170
ty: ty.lower(env)?,
167-
}),
168-
chalk_ir::WhereClause::Implemented(projection.trait_ref.lower(env)?),
169-
],
171+
}));
172+
set.insert(chalk_ir::WhereClause::Implemented(
173+
projection.trait_ref.lower(env)?,
174+
));
175+
set
176+
}
170177
WhereClause::LifetimeOutlives { a, b } => {
171-
vec![chalk_ir::WhereClause::LifetimeOutlives(
178+
let mut set = IndexSet::new();
179+
set.insert(chalk_ir::WhereClause::LifetimeOutlives(
172180
chalk_ir::LifetimeOutlives {
173181
a: a.lower(env)?,
174182
b: b.lower(env)?,
175183
},
176-
)]
184+
));
185+
set
177186
}
178187
WhereClause::TypeOutlives { ty, lifetime } => {
179-
vec![chalk_ir::WhereClause::TypeOutlives(
188+
let mut set = IndexSet::new();
189+
set.insert(chalk_ir::WhereClause::TypeOutlives(
180190
chalk_ir::TypeOutlives {
181191
ty: ty.lower(env)?,
182192
lifetime: lifetime.lower(env)?,
183193
},
184-
)]
194+
));
195+
set
185196
}
186197
})
187198
}
188199
}
189200

190201
impl LowerWithEnv for QuantifiedWhereClause {
191-
type Lowered = Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
202+
type Lowered = IndexSet<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
192203

193204
/// Lower from an AST `where` clause to an internal IR.
194205
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
@@ -298,7 +309,11 @@ impl LowerWithEnv for (&AdtDefn, chalk_ir::AdtId<ChalkIr>) {
298309
Ok(rust_ir::AdtVariantDatum { fields: fields? })
299310
})
300311
.collect::<LowerResult<_>>()?,
301-
where_clauses: adt_defn.where_clauses.lower(env)?,
312+
where_clauses: adt_defn
313+
.where_clauses
314+
.lower(env)?
315+
.into_iter()
316+
.collect::<Vec<_>>(),
302317
})
303318
})?;
304319

@@ -340,7 +355,11 @@ impl LowerWithEnv for (&FnDefn, chalk_ir::FnDefId<ChalkIr>) {
340355
let (fn_defn, fn_def_id) = self;
341356

342357
let binders = env.in_binders(fn_defn.all_parameters(), |env| {
343-
let where_clauses = fn_defn.where_clauses.lower(env)?;
358+
let where_clauses = fn_defn
359+
.where_clauses
360+
.lower(env)?
361+
.into_iter()
362+
.collect::<Vec<_>>();
344363

345364
let inputs_and_output = env.in_binders(vec![], |env| {
346365
let args: LowerResult<_> = fn_defn
@@ -542,7 +561,7 @@ impl LowerWithEnv for QuantifiedInlineBound {
542561
}
543562

544563
impl LowerWithEnv for [QuantifiedInlineBound] {
545-
type Lowered = Vec<rust_ir::QuantifiedInlineBound<ChalkIr>>;
564+
type Lowered = IndexSet<rust_ir::QuantifiedInlineBound<ChalkIr>>;
546565

547566
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
548567
fn trait_identifier(bound: &InlineBound) -> &Identifier {
@@ -899,7 +918,11 @@ impl LowerWithEnv for (&Impl, ImplId<ChalkIr>, &AssociatedTyValueIds) {
899918
))?;
900919
}
901920

902-
let where_clauses = impl_.where_clauses.lower(&env)?;
921+
let where_clauses = impl_
922+
.where_clauses
923+
.lower(&env)?
924+
.into_iter()
925+
.collect::<Vec<_>>();
903926
debug!(where_clauses = ?trait_ref);
904927
Ok(rust_ir::ImplDatumBound {
905928
trait_ref,
@@ -986,7 +1009,11 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId<ChalkIr>) {
9861009
}
9871010

9881011
Ok(rust_ir::TraitDatumBound {
989-
where_clauses: trait_defn.where_clauses.lower(env)?,
1012+
where_clauses: trait_defn
1013+
.where_clauses
1014+
.lower(env)?
1015+
.into_iter()
1016+
.collect::<Vec<_>>(),
9901017
})
9911018
})?;
9921019

chalk-integration/src/lowering/program_lowerer.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ impl ProgramLowerer {
6666
let addl_variable_kinds = defn.all_parameters();
6767
let lookup = AssociatedTyLookup {
6868
id: AssocTypeId(self.next_item_id()),
69-
addl_variable_kinds: addl_variable_kinds.anonymize(),
69+
addl_variable_kinds: addl_variable_kinds
70+
.into_iter()
71+
.collect::<Vec<_>>()
72+
.anonymize(),
7073
};
7174
self.associated_ty_lookups
7275
.insert((TraitId(raw_id), defn.name.str.clone()), lookup);
@@ -295,9 +298,13 @@ impl ProgramLowerer {
295298
variable_kinds.extend(trait_defn.all_parameters());
296299

297300
let binders = empty_env.in_binders(variable_kinds, |env| {
301+
let i1 = assoc_ty_defn.bounds.lower(&env)?;
302+
let i2 = assoc_ty_defn.where_clauses.lower(&env)?;
303+
let v1 = i1.into_iter().collect::<Vec<_>>();
304+
let v2 = i2.into_iter().collect::<Vec<_>>();
298305
Ok(rust_ir::AssociatedTyDatumBound {
299-
bounds: assoc_ty_defn.bounds.lower(&env)?,
300-
where_clauses: assoc_ty_defn.where_clauses.lower(&env)?,
306+
bounds: v1,
307+
where_clauses: v2,
301308
})
302309
})?;
303310

@@ -393,8 +400,7 @@ impl ProgramLowerer {
393400
.collect())
394401
},
395402
)?;
396-
let where_clauses: chalk_ir::Binders<Vec<chalk_ir::Binders<_>>> = env
397-
.in_binders(
403+
let where_clauses = env.in_binders(
398404
Some(chalk_ir::WithKind::new(
399405
chalk_ir::VariableKind::Ty(TyVariableKind::General),
400406
Atom::from(FIXME_SELF),
@@ -518,7 +524,10 @@ macro_rules! lower_type_kind {
518524
sort: TypeSort::$sort,
519525
name: self.name.str.clone(),
520526
binders: chalk_ir::Binders::new(
521-
VariableKinds::from_iter(ChalkIr, $params(self).anonymize()),
527+
VariableKinds::from_iter(
528+
ChalkIr,
529+
$params(self).into_iter().collect::<Vec<_>>().anonymize(),
530+
),
522531
crate::Unit,
523532
),
524533
})

0 commit comments

Comments
 (0)