Skip to content

Commit b957933

Browse files
committed
inline type computations
1 parent 6980af7 commit b957933

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

crates/environ/src/component/types_builder.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,13 @@ impl ComponentTypesBuilder {
594594
size: u32,
595595
) -> TypeFixedSizeListIndex {
596596
let element_abi = self.component_types.canonical_abi(&element);
597-
let abi = CanonicalAbiInfo::record((0..size).map(|_| element_abi));
597+
let mut abi = element_abi.clone();
598+
// this assumes that size32 is already rounded up to alignment
599+
abi.size32 = element_abi.size32 * size;
600+
abi.size64 = element_abi.size64 * size;
601+
abi.flat_count = element_abi
602+
.flat_count
603+
.map(|c| c.saturating_mul(size.min(255) as u8));
598604
self.add_fixed_size_list_type(TypeFixedSizeList { element, size, abi })
599605
}
600606

@@ -1115,7 +1121,21 @@ impl TypeInformation {
11151121
}
11161122

11171123
fn fixed_size_lists(&mut self, types: &ComponentTypesBuilder, ty: &TypeFixedSizeList) {
1118-
self.build_record((0..ty.size).map(|_| types.type_information(&ty.element)));
1124+
let element_info = types.type_information(&ty.element);
1125+
self.depth = 1 + element_info.depth;
1126+
self.has_borrow = element_info.has_borrow;
1127+
match element_info.flat.as_flat_types() {
1128+
Some(types) => {
1129+
'outer: for _ in 0..ty.size {
1130+
for (t32, t64) in types.memory32.iter().zip(types.memory64) {
1131+
if self.flat.push(*t32, *t64) {
1132+
break 'outer;
1133+
}
1134+
}
1135+
}
1136+
}
1137+
None => self.flat.len = u8::try_from(MAX_FLAT_TYPES + 1).unwrap(),
1138+
}
11191139
}
11201140

11211141
fn enums(&mut self, _types: &ComponentTypesBuilder, _ty: &TypeEnum) {

0 commit comments

Comments
 (0)