Skip to content

Commit 2d1b754

Browse files
committed
Change AdtRepr to be a struct of bools and store it in a separate map
1 parent ca7ffd4 commit 2d1b754

File tree

7 files changed

+37
-30
lines changed

7 files changed

+37
-30
lines changed

chalk-integration/src/db.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl RustIrDatabase<ChalkIr> for ChalkDatabase {
110110
}
111111

112112
fn adt_repr(&self, id: AdtId<ChalkIr>) -> AdtRepr {
113-
self.program_ir().unwrap().adt_datum(id).repr
113+
self.program_ir().unwrap().adt_repr(id)
114114
}
115115

116116
fn fn_def_datum(&self, id: FnDefId<ChalkIr>) -> Arc<FnDefDatum<ChalkIr>> {

chalk-integration/src/lowering.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl LowerProgram for Program {
412412
}
413413

414414
let mut adt_data = BTreeMap::new();
415+
let mut adt_reprs = BTreeMap::new();
415416
let mut fn_def_data = BTreeMap::new();
416417
let mut closure_inputs_and_output = BTreeMap::new();
417418
let mut closure_closure_kind = BTreeMap::new();
@@ -446,6 +447,7 @@ impl LowerProgram for Program {
446447
Item::StructDefn(ref d) => {
447448
let adt_id = AdtId(raw_id);
448449
adt_data.insert(adt_id, Arc::new(d.lower_adt(adt_id, &empty_env)?));
450+
adt_reprs.insert(adt_id, d.lower_adt_repr()?);
449451
}
450452
Item::FnDefn(ref defn) => {
451453
let fn_def_id = FnDefId(raw_id);
@@ -639,6 +641,7 @@ impl LowerProgram for Program {
639641
fn_def_kinds,
640642
trait_kinds,
641643
adt_data,
644+
adt_reprs,
642645
fn_def_data,
643646
closure_inputs_and_output,
644647
closure_closure_kind,
@@ -1113,17 +1116,23 @@ impl LowerAdtDefn for StructDefn {
11131116
phantom_data: self.flags.phantom_data,
11141117
};
11151118

1116-
let repr = match self.repr {
1117-
StructRepr::Rust => rust_ir::AdtRepr::Rust,
1118-
StructRepr::C => rust_ir::AdtRepr::C,
1119-
StructRepr::Packed => rust_ir::AdtRepr::Packed,
1120-
};
1121-
11221119
Ok(rust_ir::AdtDatum {
11231120
id: adt_id,
11241121
binders,
11251122
flags,
1126-
repr,
1123+
})
1124+
}
1125+
}
1126+
1127+
trait LowerAdtRepr {
1128+
fn lower_adt_repr(&self) -> LowerResult<rust_ir::AdtRepr>;
1129+
}
1130+
1131+
impl LowerAdtRepr for StructDefn {
1132+
fn lower_adt_repr(&self) -> LowerResult<rust_ir::AdtRepr> {
1133+
Ok(rust_ir::AdtRepr {
1134+
repr_c: self.repr.repr_c,
1135+
repr_packed: self.repr.repr_packed,
11271136
})
11281137
}
11291138
}

chalk-integration/src/program.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ pub struct Program {
4545
/// For each ADT:
4646
pub adt_data: BTreeMap<AdtId<ChalkIr>, Arc<AdtDatum<ChalkIr>>>,
4747

48+
pub adt_reprs: BTreeMap<AdtId<ChalkIr>, AdtRepr>,
49+
4850
pub fn_def_data: BTreeMap<FnDefId<ChalkIr>, Arc<FnDefDatum<ChalkIr>>>,
4951

5052
pub closure_inputs_and_output:
@@ -361,7 +363,7 @@ impl RustIrDatabase<ChalkIr> for Program {
361363
}
362364

363365
fn adt_repr(&self, id: AdtId<ChalkIr>) -> AdtRepr {
364-
self.adt_data[&id].repr
366+
self.adt_reprs[&id]
365367
}
366368

367369
fn fn_def_datum(&self, id: FnDefId<ChalkIr>) -> Arc<FnDefDatum<ChalkIr>> {

chalk-parse/src/ast.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,9 @@ pub struct StructFlags {
4747
}
4848

4949
#[derive(Clone, PartialEq, Eq, Debug)]
50-
pub enum StructRepr {
51-
Rust,
52-
C,
53-
Packed,
54-
}
55-
56-
impl Default for StructRepr {
57-
fn default() -> Self {
58-
StructRepr::Rust
59-
}
50+
pub struct StructRepr {
51+
pub repr_c: bool,
52+
pub repr_packed: bool,
6053
}
6154

6255
#[derive(Clone, PartialEq, Eq, Debug)]

chalk-parse/src/parser.lalrpop

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,11 @@ WellKnownTrait: WellKnownTrait = {
5959
"#" "[" "lang" "(" "unsize" ")" "]" => WellKnownTrait::Unsize,
6060
};
6161

62-
StructRepr: StructRepr = {
63-
"#" "[" "repr" "(" "C" ")" "]" => StructRepr::C,
64-
"#" "[" "repr" "(" "packed" ")" "]" => StructRepr::Packed,
65-
};
62+
StructReprC: () = "#" "[" "repr" "(" "C" ")" "]";
63+
StructReprPacked: () = "#" "[" "repr" "(" "packed" ")" "]";
6664

6765
StructDefn: StructDefn = {
68-
<upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> <phantom_data:PhantomDataKeyword?> <repr:StructRepr?>
66+
<upstream:UpstreamKeyword?> <fundamental:FundamentalKeyword?> <phantom_data:PhantomDataKeyword?> <repr_c:StructReprC?> <repr_packed:StructReprPacked?>
6967
"struct" <n:Id><p:Angle<VariableKind>>
7068
<w:QuantifiedWhereClauses> "{" <f:Fields> "}" => StructDefn
7169
{
@@ -78,7 +76,10 @@ StructDefn: StructDefn = {
7876
fundamental: fundamental.is_some(),
7977
phantom_data: phantom_data.is_some(),
8078
},
81-
repr: repr.unwrap_or_default(),
79+
repr: StructRepr {
80+
repr_c: repr_c.is_some(),
81+
repr_packed: repr_packed.is_some(),
82+
},
8283
}
8384
};
8485

chalk-solve/src/rust_ir.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ pub struct AdtDatum<I: Interner> {
8383
pub binders: Binders<AdtDatumBound<I>>,
8484
pub id: AdtId<I>,
8585
pub flags: AdtFlags,
86-
pub repr: AdtRepr,
8786
}
8887

8988
impl<I: Interner> AdtDatum<I> {
@@ -106,10 +105,9 @@ pub struct AdtFlags {
106105
}
107106

108107
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
109-
pub enum AdtRepr {
110-
Rust,
111-
C,
112-
Packed,
108+
pub struct AdtRepr {
109+
pub repr_c: bool,
110+
pub repr_packed: bool,
113111
}
114112

115113
#[derive(Clone, Debug, PartialEq, Eq, Hash)]

tests/lowering/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,10 @@ fn struct_repr() {
747747

748748
#[repr(packed)]
749749
struct Bar {}
750+
751+
#[repr(C)]
752+
#[repr(packed)]
753+
struct FooBar {}
750754
}
751755
}
752756
}

0 commit comments

Comments
 (0)