Skip to content

Commit f90166f

Browse files
committed
deduplicate code in inline.rs
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 8986c00 commit f90166f

File tree

1 file changed

+6
-30
lines changed
  • crates/environ/src/component/translate

1 file changed

+6
-30
lines changed

crates/environ/src/component/translate/inline.rs

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1276,37 +1276,13 @@ impl<'a> Inliner<'a> {
12761276
types: &ComponentTypesBuilder,
12771277
options: &LocalCanonicalOptions,
12781278
) -> AdapterOptions {
1279-
let memory = options.memory.map(|i| {
1280-
frame.memories[i].clone().map_index(|i| match i {
1281-
EntityIndex::Memory(i) => i,
1282-
_ => unreachable!(),
1279+
let (memory, memory64) = options
1280+
.memory
1281+
.map(|i| {
1282+
let (memory, memory64) = self.memory(frame, types, i);
1283+
(Some(memory), memory64)
12831284
})
1284-
});
1285-
let memory64 = match &memory {
1286-
Some(memory) => match &self.runtime_instances[memory.instance] {
1287-
InstanceModule::Static(idx) => match &memory.item {
1288-
ExportItem::Index(i) => {
1289-
let ty = &self.nested_modules[*idx].module.memories[*i];
1290-
match ty.idx_type {
1291-
IndexType::I32 => false,
1292-
IndexType::I64 => true,
1293-
}
1294-
}
1295-
ExportItem::Name(_) => unreachable!(),
1296-
},
1297-
InstanceModule::Import(ty) => match &memory.item {
1298-
ExportItem::Name(name) => match types[*ty].exports[name] {
1299-
EntityType::Memory(m) => match m.idx_type {
1300-
IndexType::I32 => false,
1301-
IndexType::I64 => true,
1302-
},
1303-
_ => unreachable!(),
1304-
},
1305-
ExportItem::Index(_) => unreachable!(),
1306-
},
1307-
},
1308-
None => false,
1309-
};
1285+
.unwrap_or((None, false));
13101286
let realloc = options.realloc.map(|i| frame.funcs[i].clone());
13111287
let callback = options.callback.map(|i| frame.funcs[i].clone());
13121288
let post_return = options.post_return.map(|i| frame.funcs[i].clone());

0 commit comments

Comments
 (0)