mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Begin generating semantic reprs for records
This commit is contained in:
parent
6714a6fd92
commit
c06ffc434b
4 changed files with 40 additions and 12 deletions
|
@ -663,7 +663,7 @@ impl FieldOrderHash {
|
||||||
const ZERO_FIELD_HASH: Self = Self(0);
|
const ZERO_FIELD_HASH: Self = Self(0);
|
||||||
const IRRELEVANT_NON_ZERO_FIELD_HASH: Self = Self(1);
|
const IRRELEVANT_NON_ZERO_FIELD_HASH: Self = Self(1);
|
||||||
|
|
||||||
pub fn from_ordered_fields(fields: &[&Lowercase]) -> Self {
|
pub fn from_ordered_fields(fields: &[&str]) -> Self {
|
||||||
if fields.is_empty() {
|
if fields.is_empty() {
|
||||||
// HACK: we must make sure this is always equivalent to a `ZERO_FIELD_HASH`.
|
// HACK: we must make sure this is always equivalent to a `ZERO_FIELD_HASH`.
|
||||||
return Self::ZERO_FIELD_HASH;
|
return Self::ZERO_FIELD_HASH;
|
||||||
|
@ -3262,8 +3262,12 @@ fn layout_from_flat_type<'a>(
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
let ordered_field_names =
|
let ordered_field_names = Vec::from_iter_in(
|
||||||
Vec::from_iter_in(sortables.iter().map(|(label, _)| *label), arena);
|
sortables
|
||||||
|
.iter()
|
||||||
|
.map(|(label, _)| &*arena.alloc_str(label.as_str())),
|
||||||
|
arena,
|
||||||
|
);
|
||||||
let field_order_hash =
|
let field_order_hash =
|
||||||
FieldOrderHash::from_ordered_fields(ordered_field_names.as_slice());
|
FieldOrderHash::from_ordered_fields(ordered_field_names.as_slice());
|
||||||
|
|
||||||
|
@ -3278,7 +3282,7 @@ fn layout_from_flat_type<'a>(
|
||||||
field_order_hash,
|
field_order_hash,
|
||||||
field_layouts: layouts.into_bump_slice(),
|
field_layouts: layouts.into_bump_slice(),
|
||||||
},
|
},
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::record(ordered_field_names.into_bump_slice()),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(env.cache.put_in(struct_layout))
|
Ok(env.cache.put_in(struct_layout))
|
||||||
|
|
|
@ -127,7 +127,7 @@ impl<'a> Layout<'a> {
|
||||||
field_layouts: &[],
|
field_layouts: &[],
|
||||||
field_order_hash: FieldOrderHash::ZERO_FIELD_HASH,
|
field_order_hash: FieldOrderHash::ZERO_FIELD_HASH,
|
||||||
},
|
},
|
||||||
semantic: SemanticRepr::None,
|
semantic: SemanticRepr::EMPTY_RECORD,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const fn float_width(w: FloatWidth) -> InLayout<'static> {
|
pub const fn float_width(w: FloatWidth) -> InLayout<'static> {
|
||||||
|
|
24
crates/compiler/mono/src/layout/semantic.rs
Normal file
24
crates/compiler/mono/src/layout/semantic.rs
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
//! Semantic representations of memory layouts for the purposes of specialization.
|
||||||
|
|
||||||
|
/// A semantic representation of a memory layout.
|
||||||
|
/// Semantic representations describe the shape of a type a [Layout][super::Layout] is generated
|
||||||
|
/// for. Semantic representations disambiguate types that have the same runtime memory layout, but
|
||||||
|
/// different shapes.
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
pub enum SemanticRepr<'a> {
|
||||||
|
None,
|
||||||
|
Record(SemaRecord<'a>),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> SemanticRepr<'a> {
|
||||||
|
pub(super) const EMPTY_RECORD: Self = Self::Record(SemaRecord { fields: &[] });
|
||||||
|
|
||||||
|
pub(super) fn record(fields: &'a [&'a str]) -> Self {
|
||||||
|
Self::Record(SemaRecord { fields })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
pub struct SemaRecord<'a> {
|
||||||
|
pub fields: &'a [&'a str],
|
||||||
|
}
|
|
@ -8,8 +8,8 @@ procedure Str.3 (#Attr.2, #Attr.3):
|
||||||
|
|
||||||
procedure Test.11 (Test.29, #Attr.12):
|
procedure Test.11 (Test.29, #Attr.12):
|
||||||
let Test.10 : {} = UnionAtIndex (Id 0) (Index 0) #Attr.12;
|
let Test.10 : {} = UnionAtIndex (Id 0) (Index 0) #Attr.12;
|
||||||
let #Derived_gen.2 : Int1 = lowlevel RefCountIsUnique #Attr.12;
|
let #Derived_gen.0 : Int1 = lowlevel RefCountIsUnique #Attr.12;
|
||||||
if #Derived_gen.2 then
|
if #Derived_gen.0 then
|
||||||
decref #Attr.12;
|
decref #Attr.12;
|
||||||
ret Test.10;
|
ret Test.10;
|
||||||
else
|
else
|
||||||
|
@ -23,7 +23,7 @@ procedure Test.14 (Test.62, Test.63):
|
||||||
joinpoint Test.37 Test.36 #Attr.12:
|
joinpoint Test.37 Test.36 #Attr.12:
|
||||||
let Test.12 : {} = UnionAtIndex (Id 1) (Index 1) #Attr.12;
|
let Test.12 : {} = UnionAtIndex (Id 1) (Index 1) #Attr.12;
|
||||||
let Test.13 : I64 = UnionAtIndex (Id 1) (Index 0) #Attr.12;
|
let Test.13 : I64 = UnionAtIndex (Id 1) (Index 0) #Attr.12;
|
||||||
joinpoint #Derived_gen.0:
|
joinpoint #Derived_gen.1:
|
||||||
let Test.43 : {} = Struct {};
|
let Test.43 : {} = Struct {};
|
||||||
let Test.42 : {} = CallByName Test.11 Test.43 Test.12;
|
let Test.42 : {} = CallByName Test.11 Test.43 Test.12;
|
||||||
let Test.38 : [<r>C {}, C I64 {}] = CallByName Test.9 Test.42 Test.13;
|
let Test.38 : [<r>C {}, C I64 {}] = CallByName Test.9 Test.42 Test.13;
|
||||||
|
@ -38,13 +38,13 @@ procedure Test.14 (Test.62, Test.63):
|
||||||
jump Test.37 Test.40 Test.38;
|
jump Test.37 Test.40 Test.38;
|
||||||
|
|
||||||
in
|
in
|
||||||
let #Derived_gen.1 : Int1 = lowlevel RefCountIsUnique #Attr.12;
|
let #Derived_gen.2 : Int1 = lowlevel RefCountIsUnique #Attr.12;
|
||||||
if #Derived_gen.1 then
|
if #Derived_gen.2 then
|
||||||
decref #Attr.12;
|
decref #Attr.12;
|
||||||
jump #Derived_gen.0;
|
jump #Derived_gen.1;
|
||||||
else
|
else
|
||||||
decref #Attr.12;
|
decref #Attr.12;
|
||||||
jump #Derived_gen.0;
|
jump #Derived_gen.1;
|
||||||
in
|
in
|
||||||
jump Test.37 Test.62 Test.63;
|
jump Test.37 Test.62 Test.63;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue