Skip to content

Commit 939926a

Browse files
committed
Store object safety knowledge in Program instead of TraitDatum
1 parent 7360bbd commit 939926a

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

chalk-integration/src/lowering.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use chalk_rust_ir as rust_ir;
1010
use chalk_rust_ir::{
1111
Anonymize, AssociatedTyValueId, IntoWhereClauses, OpaqueTyDatum, OpaqueTyDatumBound,
1212
};
13-
use std::collections::BTreeMap;
13+
use std::collections::{BTreeMap, HashSet};
1414
use std::sync::Arc;
1515
use string_cache::DefaultAtom as Atom;
1616

@@ -243,6 +243,7 @@ impl LowerProgram for Program {
243243
let mut struct_kinds = BTreeMap::new();
244244
let mut trait_kinds = BTreeMap::new();
245245
let mut opaque_ty_kinds = BTreeMap::new();
246+
let mut object_safe_traits = HashSet::new();
246247
for (item, &raw_id) in self.items.iter().zip(&raw_ids) {
247248
match item {
248249
Item::StructDefn(defn) => {
@@ -256,6 +257,10 @@ impl LowerProgram for Program {
256257
let id = TraitId(raw_id);
257258
trait_ids.insert(type_kind.name.clone(), id);
258259
trait_kinds.insert(id, type_kind);
260+
261+
if defn.flags.object_safe {
262+
object_safe_traits.insert(id);
263+
}
259264
}
260265
Item::OpaqueTyDefn(defn) => {
261266
let type_kind = defn.lower_type_kind()?;
@@ -457,6 +462,7 @@ impl LowerProgram for Program {
457462
opaque_ty_kinds,
458463
opaque_ty_data,
459464
custom_clauses,
465+
object_safe_traits,
460466
};
461467

462468
Ok(program)
@@ -1019,7 +1025,6 @@ impl LowerTraitFlags for TraitFlags {
10191025
fundamental: self.fundamental,
10201026
non_enumerable: self.non_enumerable,
10211027
coinductive: self.coinductive,
1022-
object_safe: self.object_safe,
10231028
}
10241029
}
10251030
}

chalk-integration/src/program.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use chalk_rust_ir::{
1313
};
1414
use chalk_solve::split::Split;
1515
use chalk_solve::RustIrDatabase;
16-
use std::collections::BTreeMap;
16+
use std::collections::{BTreeMap, HashSet};
1717
use std::fmt;
1818
use std::sync::Arc;
1919

@@ -61,6 +61,9 @@ pub struct Program {
6161

6262
/// For each user-specified clause
6363
pub custom_clauses: Vec<ProgramClause<ChalkIr>>,
64+
65+
/// Store the traits marked with `#[object_safe]`
66+
pub object_safe_traits: HashSet<TraitId<ChalkIr>>,
6467
}
6568

6669
impl Program {
@@ -394,6 +397,6 @@ impl RustIrDatabase<ChalkIr> for Program {
394397
}
395398

396399
fn is_object_safe(&self, trait_id: TraitId<ChalkIr>) -> bool {
397-
self.trait_datum(trait_id).is_object_safe_trait()
400+
self.object_safe_traits.contains(&trait_id)
398401
}
399402
}

chalk-rust-ir/src/lib.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ impl<I: Interner> TraitDatum<I> {
168168
self.flags.coinductive
169169
}
170170

171-
pub fn is_object_safe_trait(&self) -> bool {
172-
self.flags.object_safe
173-
}
174-
175171
/// Gives access to the where clauses of the trait, quantified over the type parameters of the trait:
176172
///
177173
/// ```ignore
@@ -225,9 +221,6 @@ pub struct TraitFlags {
225221
pub non_enumerable: bool,
226222

227223
pub coinductive: bool,
228-
229-
/// Indicates that a trait is object safe
230-
pub object_safe: bool,
231224
}
232225

233226
/// An inline bound, e.g. `: Foo<K>` in `impl<K, T: Foo<K>> SomeType<T>`.

0 commit comments

Comments
 (0)