Skip to content

Commit 4ae7cd1

Browse files
committed
Use maps instead of vectors for the trait clause params
1 parent a9b8cae commit 4ae7cd1

File tree

6 files changed

+25
-12
lines changed

6 files changed

+25
-12
lines changed

charon/src/assumed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::ullbc_ast;
1111
use macros::EnumIsA;
1212

1313
/// Ignore the builtin/auto traits like [core::marker::Sized] or [core::marker::Sync].
14-
pub const IGNORE_BUILTIN_MARKER_TRAITS: bool = false;
14+
pub const IGNORE_BUILTIN_MARKER_TRAITS: bool = true;
1515

1616
// Ignored traits (includes marker traits, and others)
1717
pub static MARKER_SIZED_NAME: [&str; 3] = ["core", "marker", "Sized"];

charon/src/reorder_decls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ impl Deps {
406406

407407
fn visit_generics_and_preds(&mut self, generics: &GenericParams, preds: &Predicates) {
408408
// Visit the traits referenced in the generics
409-
for clause in &generics.trait_clauses {
409+
for clause in generics.trait_clauses.values() {
410410
self.visit_trait_clause(clause);
411411
}
412412

charon/src/translate_ctx.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_hir::def_id::DefId;
2121
use rustc_middle::ty::TyCtxt;
2222
use rustc_session::Session;
2323
use std::cmp::{Ord, Ordering, PartialOrd};
24-
use std::collections::{BTreeSet, HashMap, HashSet, VecDeque};
24+
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
2525
use std::fmt;
2626

2727
/// Macro to either panic or return on error, depending on the CLI options
@@ -953,14 +953,22 @@ impl<'tcx, 'ctx, 'ctx1> BodyTransCtx<'tcx, 'ctx, 'ctx1> {
953953

954954
/// Retrieve the *local* trait clauses available in the current environment
955955
/// (we filter the parent of those clauses, etc.).
956-
pub(crate) fn get_local_trait_clauses(&self) -> TraitClauseId::Vector<TraitClause> {
957-
let clauses: TraitClauseId::Vector<TraitClause> = self
956+
pub(crate) fn get_local_trait_clauses(&self) -> BTreeMap<TraitClauseId::Id, TraitClause> {
957+
let clauses: Vec<TraitClause> = self
958958
.trait_clauses
959959
.iter()
960960
.filter_map(|(_, x)| x.to_local_trait_clause())
961961
.collect();
962962
// Sanity check
963-
assert!(clauses.iter_indexed_values().all(|(i, c)| c.clause_id == i));
963+
if !crate::assumed::IGNORE_BUILTIN_MARKER_TRAITS {
964+
use crate::id_vector::ToUsize;
965+
assert!(clauses
966+
.iter()
967+
.enumerate()
968+
.all(|(i, c)| c.clause_id.to_usize() == i));
969+
}
970+
let clauses: BTreeMap<TraitClauseId::Id, TraitClause> =
971+
clauses.into_iter().map(|x| (x.clause_id, x)).collect();
964972
clauses
965973
}
966974

charon/src/translate_traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'tcx, 'ctx> TransCtx<'tcx, 'ctx> {
403403
.join("\n");
404404
let generic_clauses = generics
405405
.trait_clauses
406-
.iter()
406+
.values()
407407
.map(|c| c.fmt_with_ctx(&ctx))
408408
.collect::<Vec<String>>()
409409
.join("\n");

charon/src/types.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use macros::{
88
generate_index_type, EnumAsGetters, EnumIsA, EnumToGetters, VariantIndexArity, VariantName,
99
};
1010
use serde::Serialize;
11+
use std::collections::BTreeMap;
1112

1213
pub type FieldName = String;
1314

@@ -299,7 +300,10 @@ pub struct GenericParams {
299300
pub types: TypeVarId::Vector<TypeVar>,
300301
pub const_generics: ConstGenericVarId::Vector<ConstGenericVar>,
301302
// TODO: rename to match [GenericArgs]?
302-
pub trait_clauses: TraitClauseId::Vector<TraitClause>,
303+
// Remark: this is an OrdMap, not a vector, because due to the filtering
304+
// of some trait clauses (for the marker traits for instance) the indexation
305+
// is not contiguous.
306+
pub trait_clauses: BTreeMap<TraitClauseId::Id, TraitClause>,
303307
}
304308

305309
generate_index_type!(TraitClauseId);

charon/src/types_utils.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::values::*;
77
use hax_frontend_exporter as hax;
88
use im::HashMap;
99
use macros::make_generic_in_borrows;
10+
use std::collections::BTreeMap;
1011
use std::iter::Iterator;
1112

1213
impl DeBruijnId {
@@ -93,7 +94,7 @@ impl GenericParams {
9394
regions: RegionId::Vector::new(),
9495
types: TypeVarId::Vector::new(),
9596
const_generics: ConstGenericVarId::Vector::new(),
96-
trait_clauses: TraitClauseId::Vector::new(),
97+
trait_clauses: BTreeMap::new(),
9798
}
9899
}
99100

@@ -120,7 +121,7 @@ impl GenericParams {
120121
for x in const_generics {
121122
params.push(x.to_string());
122123
}
123-
for x in trait_clauses {
124+
for x in trait_clauses.values() {
124125
params.push(x.fmt_with_ctx(ctx));
125126
}
126127
format!("<{}>", params.join(", "))
@@ -154,7 +155,7 @@ impl GenericParams {
154155
};
155156

156157
let mut clauses = Vec::new();
157-
for x in trait_clauses {
158+
for x in trait_clauses.values() {
158159
clauses.push(x.fmt_with_ctx(ctx));
159160
}
160161
(params, clauses)
@@ -1373,7 +1374,7 @@ pub trait TypeVisitor {
13731374
for cg in g.const_generics.iter() {
13741375
self.visit_const_generic_var(cg);
13751376
}
1376-
for t in g.trait_clauses.iter() {
1377+
for (_, t) in g.trait_clauses.iter() {
13771378
self.visit_trait_clause(t);
13781379
}
13791380
}

0 commit comments

Comments
 (0)