Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Ord from chalk_ir::interner::DefId #739

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
664d12d
Remove `Ord` from `chalk_ir::interner::Interner::DefId`
pierwill Dec 14, 2021
a441bfd
Remove `Ord`/`PartialOrd` from `chalk_solve::display::state::UnifiedId`
pierwill Dec 14, 2021
cb1e147
Remove `Ord` from `IdAliasStore` generic
pierwill Dec 14, 2021
50b9298
Remove `Ord` from Interner and assoc types
pierwill Dec 14, 2021
8727138
Add `indexmap` crate
pierwill Dec 14, 2021
1356f6d
Rm Ord from ChalkIr
pierwill Dec 14, 2021
dd5ff49
Use `indexmap` throughout
pierwill Dec 14, 2021
0dd9b31
Remove Ord from id types
pierwill Dec 14, 2021
eb914bb
Do not add nodes that already exist
pierwill Dec 14, 2021
fcc3485
Use indexmap 1.5.1 (same as rustc)
pierwill Dec 15, 2021
8f1d6e8
Add fixme notice
pierwill Dec 15, 2021
6408a3a
Add indexmap to chalk-parse
pierwill Dec 15, 2021
75f8283
Add Hash traits where needed
pierwill Dec 15, 2021
7a80b58
Use indexset for where_clauses
pierwill Dec 15, 2021
cfe63d7
Use indexset in impl LowerWithEnv for [QuantifiedInlineBound]
pierwill Dec 15, 2021
cd602c6
parser.lalrpop: use IndexSet for QuantifiedWhereClauses
pierwill Dec 15, 2021
b964a3a
AST: use IndexSet for `where_clause`s
pierwill Dec 15, 2021
a8525b6
Use IndexSet in lowering.rs
pierwill Dec 15, 2021
aa6c89e
Use indexsets
pierwill Dec 15, 2021
b3a8152
Revert "Use indexsets"
pierwill Dec 15, 2021
6f6e3be
Revert "Use IndexSet in lowering.rs"
pierwill Dec 15, 2021
5029521
Revert "AST: use IndexSet for `where_clause`s"
pierwill Dec 15, 2021
f1e4ef6
Revert "parser.lalrpop: use IndexSet for QuantifiedWhereClauses"
pierwill Dec 15, 2021
5203a21
Revert "Use indexset in impl LowerWithEnv for [QuantifiedInlineBound]"
pierwill Dec 15, 2021
fa1e5d4
Revert "Use indexset for where_clauses"
pierwill Dec 15, 2021
0cd329f
Revert "Add Hash traits where needed"
pierwill Dec 15, 2021
51422d9
Revert "Add indexmap to chalk-parse"
pierwill Dec 15, 2021
0525fc1
Revert "Add fixme notice"
pierwill Dec 15, 2021
5300364
Impl HasInterner for IndexSet
pierwill Dec 15, 2021
76fd010
Convert from IndexSet to Vec in lowering
pierwill Dec 15, 2021
72c573e
Finish lowering conversions
pierwill Dec 15, 2021
6a8956c
Another set use
pierwill Dec 15, 2021
14f7319
another attempt to fix...
pierwill Dec 15, 2021
f9ca7ae
use indexset! macro in lowering code
pierwill Dec 16, 2021
f7ac051
bump back indexmap
pierwill Dec 16, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions chalk-integration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ chalk-solve = { version = "0.76.0-dev.0", path = "../chalk-solve" }
chalk-recursive = { version = "0.76.0-dev.0", path = "../chalk-recursive" }
chalk-engine = { version = "0.76.0-dev.0", path = "../chalk-engine" }
chalk-parse = { version = "0.76.0-dev.0", path = "../chalk-parse" }
indexmap = "1.7.0"
2 changes: 1 addition & 1 deletion chalk-integration/src/interner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl Debug for ChalkFnAbi {

/// The default "interner" and the only interner used by chalk
/// itself. In this interner, no interning actually occurs.
#[derive(Debug, Copy, Clone, Hash, PartialOrd, Ord, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
pub struct ChalkIr;

impl Interner for ChalkIr {
Expand Down
80 changes: 49 additions & 31 deletions chalk-integration/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use chalk_ir::{
};
use chalk_parse::ast::*;
use chalk_solve::rust_ir::{self, IntoWhereClauses};
use indexmap::{indexset, IndexMap, IndexSet};
use program_lowerer::ProgramLowerer;
use std::collections::BTreeMap;
use string_cache::DefaultAtom as Atom;
use tracing::debug;

Expand Down Expand Up @@ -53,7 +53,7 @@ impl Lower for Program {
trait LowerParameterMap {
fn synthetic_parameters(&self) -> Option<chalk_ir::WithKind<ChalkIr, Ident>>;
fn declared_parameters(&self) -> &[VariableKind];
fn all_parameters(&self) -> Vec<chalk_ir::WithKind<ChalkIr, Ident>> {
fn all_parameters(&self) -> indexmap::IndexSet<chalk_ir::WithKind<ChalkIr, Ident>> {
self.synthetic_parameters()
.into_iter()
.chain(self.declared_parameters().iter().map(|id| id.lower()))
Expand Down Expand Up @@ -136,7 +136,7 @@ impl Lower for VariableKind {
}

impl LowerWithEnv for [QuantifiedWhereClause] {
type Lowered = Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
type Lowered = IndexSet<chalk_ir::QuantifiedWhereClause<ChalkIr>>;

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

impl LowerWithEnv for WhereClause {
type Lowered = Vec<chalk_ir::WhereClause<ChalkIr>>;
type Lowered = IndexSet<chalk_ir::WhereClause<ChalkIr>>;

/// Lower from an AST `where` clause to an internal IR.
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
Expand All @@ -158,37 +158,39 @@ impl LowerWithEnv for WhereClause {
fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
Ok(match self {
WhereClause::Implemented { trait_ref } => {
vec![chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?)]
indexset! { chalk_ir::WhereClause::Implemented(trait_ref.lower(env)?)}
}
WhereClause::ProjectionEq { projection, ty } => {
indexset! {
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
alias: chalk_ir::AliasTy::Projection(projection.lower(env)?),
ty: ty.lower(env)?}),
chalk_ir::WhereClause::Implemented(
projection.trait_ref.lower(env)?),
}
}
WhereClause::ProjectionEq { projection, ty } => vec![
chalk_ir::WhereClause::AliasEq(chalk_ir::AliasEq {
alias: chalk_ir::AliasTy::Projection(projection.lower(env)?),
ty: ty.lower(env)?,
}),
chalk_ir::WhereClause::Implemented(projection.trait_ref.lower(env)?),
],
WhereClause::LifetimeOutlives { a, b } => {
vec![chalk_ir::WhereClause::LifetimeOutlives(
indexset! {chalk_ir::WhereClause::LifetimeOutlives(
chalk_ir::LifetimeOutlives {
a: a.lower(env)?,
b: b.lower(env)?,
},
)]
)}
}
WhereClause::TypeOutlives { ty, lifetime } => {
vec![chalk_ir::WhereClause::TypeOutlives(
indexset! {chalk_ir::WhereClause::TypeOutlives(
chalk_ir::TypeOutlives {
ty: ty.lower(env)?,
lifetime: lifetime.lower(env)?,
},
)]
)}
}
})
}
}

impl LowerWithEnv for QuantifiedWhereClause {
type Lowered = Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>>;
type Lowered = IndexSet<chalk_ir::QuantifiedWhereClause<ChalkIr>>;

/// Lower from an AST `where` clause to an internal IR.
/// Some AST `where` clauses can lower to multiple ones, this is why we return a `Vec`.
Expand Down Expand Up @@ -298,7 +300,11 @@ impl LowerWithEnv for (&AdtDefn, chalk_ir::AdtId<ChalkIr>) {
Ok(rust_ir::AdtVariantDatum { fields: fields? })
})
.collect::<LowerResult<_>>()?,
where_clauses: adt_defn.where_clauses.lower(env)?,
where_clauses: adt_defn
.where_clauses
.lower(env)?
.into_iter()
.collect::<Vec<_>>(),
})
})?;

Expand Down Expand Up @@ -340,7 +346,11 @@ impl LowerWithEnv for (&FnDefn, chalk_ir::FnDefId<ChalkIr>) {
let (fn_defn, fn_def_id) = self;

let binders = env.in_binders(fn_defn.all_parameters(), |env| {
let where_clauses = fn_defn.where_clauses.lower(env)?;
let where_clauses = fn_defn
.where_clauses
.lower(env)?
.into_iter()
.collect::<Vec<_>>();

let inputs_and_output = env.in_binders(vec![], |env| {
let args: LowerResult<_> = fn_defn
Expand Down Expand Up @@ -537,12 +547,14 @@ impl LowerWithEnv for QuantifiedInlineBound {

fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
let variable_kinds = self.variable_kinds.iter().map(|k| k.lower());
env.in_binders(variable_kinds, |env| self.bound.lower(env))
let x = env.in_binders(variable_kinds, |env| self.bound.lower(env))?;
//
Ok(rust_ir::QuantifiedInlineBound(x))
}
}

impl LowerWithEnv for [QuantifiedInlineBound] {
type Lowered = Vec<rust_ir::QuantifiedInlineBound<ChalkIr>>;
type Lowered = IndexSet<rust_ir::QuantifiedInlineBound<ChalkIr>>;

fn lower(&self, env: &Env) -> LowerResult<Self::Lowered> {
fn trait_identifier(bound: &InlineBound) -> &Identifier {
Expand All @@ -552,20 +564,18 @@ impl LowerWithEnv for [QuantifiedInlineBound] {
}
}

let mut regular_traits = Vec::new();
let mut auto_traits = Vec::new();
let mut regular_traits = IndexSet::new();
let mut auto_traits = IndexSet::new();

for b in self {
let id = env.lookup_trait(trait_identifier(&b.bound))?;
if env.auto_trait(id) {
auto_traits.push((b, id))
auto_traits.insert((b, id));
} else {
regular_traits.push((b, id))
regular_traits.insert((b, id));
}
}

auto_traits.sort_by_key(|b| b.1);

regular_traits
.iter()
.chain(auto_traits.iter())
Expand Down Expand Up @@ -901,7 +911,11 @@ impl LowerWithEnv for (&Impl, ImplId<ChalkIr>, &AssociatedTyValueIds) {
))?;
}

let where_clauses = impl_.where_clauses.lower(&env)?;
let where_clauses = impl_
.where_clauses
.lower(&env)?
.into_iter()
.collect::<Vec<_>>();
debug!(where_clauses = ?trait_ref);
Ok(rust_ir::ImplDatumBound {
trait_ref,
Expand Down Expand Up @@ -988,7 +1002,11 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId<ChalkIr>) {
}

Ok(rust_ir::TraitDatumBound {
where_clauses: trait_defn.where_clauses.lower(env)?,
where_clauses: trait_defn
.where_clauses
.lower(env)?
.into_iter()
.collect::<Vec<_>>(),
})
})?;

Expand All @@ -1014,7 +1032,7 @@ impl LowerWithEnv for (&TraitDefn, chalk_ir::TraitId<ChalkIr>) {

pub fn lower_goal(goal: &Goal, program: &LoweredProgram) -> LowerResult<chalk_ir::Goal<ChalkIr>> {
let interner = ChalkIr;
let associated_ty_lookups: BTreeMap<_, _> = program
let associated_ty_lookups: IndexMap<_, _> = program
.associated_ty_data
.iter()
.map(|(&associated_ty_id, datum)| {
Expand Down Expand Up @@ -1052,7 +1070,7 @@ pub fn lower_goal(goal: &Goal, program: &LoweredProgram) -> LowerResult<chalk_ir
opaque_ty_kinds: &program.opaque_ty_kinds,
associated_ty_lookups: &associated_ty_lookups,
foreign_ty_ids: &program.foreign_ty_ids,
parameter_map: BTreeMap::new(),
parameter_map: IndexMap::new(),
auto_traits: &auto_traits,
};

Expand Down
36 changes: 18 additions & 18 deletions chalk-integration/src/lowering/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,31 @@ use chalk_ir::{
use chalk_ir::{cast::Cast, ForeignDefId, WithKind};
use chalk_parse::ast::*;
use chalk_solve::rust_ir::AssociatedTyValueId;
use std::collections::BTreeMap;
use indexmap::IndexMap;

use crate::error::RustIrError;
use crate::interner::ChalkIr;
use crate::{Identifier as Ident, TypeKind};

pub type AdtIds = BTreeMap<Ident, chalk_ir::AdtId<ChalkIr>>;
pub type FnDefIds = BTreeMap<Ident, chalk_ir::FnDefId<ChalkIr>>;
pub type ClosureIds = BTreeMap<Ident, chalk_ir::ClosureId<ChalkIr>>;
pub type TraitIds = BTreeMap<Ident, chalk_ir::TraitId<ChalkIr>>;
pub type GeneratorIds = BTreeMap<Ident, chalk_ir::GeneratorId<ChalkIr>>;
pub type OpaqueTyIds = BTreeMap<Ident, chalk_ir::OpaqueTyId<ChalkIr>>;
pub type AdtKinds = BTreeMap<chalk_ir::AdtId<ChalkIr>, TypeKind>;
pub type FnDefKinds = BTreeMap<chalk_ir::FnDefId<ChalkIr>, TypeKind>;
pub type ClosureKinds = BTreeMap<chalk_ir::ClosureId<ChalkIr>, TypeKind>;
pub type TraitKinds = BTreeMap<chalk_ir::TraitId<ChalkIr>, TypeKind>;
pub type AutoTraits = BTreeMap<chalk_ir::TraitId<ChalkIr>, bool>;
pub type OpaqueTyVariableKinds = BTreeMap<chalk_ir::OpaqueTyId<ChalkIr>, TypeKind>;
pub type GeneratorKinds = BTreeMap<chalk_ir::GeneratorId<ChalkIr>, TypeKind>;
pub type AssociatedTyLookups = BTreeMap<(chalk_ir::TraitId<ChalkIr>, Ident), AssociatedTyLookup>;
pub type AdtIds = IndexMap<Ident, chalk_ir::AdtId<ChalkIr>>;
pub type FnDefIds = IndexMap<Ident, chalk_ir::FnDefId<ChalkIr>>;
pub type ClosureIds = IndexMap<Ident, chalk_ir::ClosureId<ChalkIr>>;
pub type TraitIds = IndexMap<Ident, chalk_ir::TraitId<ChalkIr>>;
pub type GeneratorIds = IndexMap<Ident, chalk_ir::GeneratorId<ChalkIr>>;
pub type OpaqueTyIds = IndexMap<Ident, chalk_ir::OpaqueTyId<ChalkIr>>;
pub type AdtKinds = IndexMap<chalk_ir::AdtId<ChalkIr>, TypeKind>;
pub type FnDefKinds = IndexMap<chalk_ir::FnDefId<ChalkIr>, TypeKind>;
pub type ClosureKinds = IndexMap<chalk_ir::ClosureId<ChalkIr>, TypeKind>;
pub type TraitKinds = IndexMap<chalk_ir::TraitId<ChalkIr>, TypeKind>;
pub type AutoTraits = IndexMap<chalk_ir::TraitId<ChalkIr>, bool>;
pub type OpaqueTyVariableKinds = IndexMap<chalk_ir::OpaqueTyId<ChalkIr>, TypeKind>;
pub type GeneratorKinds = IndexMap<chalk_ir::GeneratorId<ChalkIr>, TypeKind>;
pub type AssociatedTyLookups = IndexMap<(chalk_ir::TraitId<ChalkIr>, Ident), AssociatedTyLookup>;
pub type AssociatedTyValueIds =
BTreeMap<(chalk_ir::ImplId<ChalkIr>, Ident), AssociatedTyValueId<ChalkIr>>;
pub type ForeignIds = BTreeMap<Ident, chalk_ir::ForeignDefId<ChalkIr>>;
IndexMap<(chalk_ir::ImplId<ChalkIr>, Ident), AssociatedTyValueId<ChalkIr>>;
pub type ForeignIds = IndexMap<Ident, chalk_ir::ForeignDefId<ChalkIr>>;

pub type ParameterMap = BTreeMap<Ident, chalk_ir::WithKind<ChalkIr, BoundVar>>;
pub type ParameterMap = IndexMap<Ident, chalk_ir::WithKind<ChalkIr, BoundVar>>;

pub type LowerResult<T> = Result<T, RustIrError>;

Expand Down
Loading