Skip to content

Commit 35584c7

Browse files
committed
Fix some unreachable!() with wasm components
This commit resolves a few panics in Wasmtime's compilation of components with respect to tags and the exception-handling wasm proposal. Despite exception-handling not being enabled in Wasmtime at this time these panics were still reachable due to an issue in wasm-tools's validation not being exhaustive enough for this proposal feature combination: bytecodealliance/wasm-tools#2114. This is not full support for exceptions since it can't be tested yet, but this should be enough to ensure that the validator will get far enough to flag components as otherwise invalid due to using tags that can't be present (as core wasm tags can't be present in core modules right now, the `EXCEPTIONS` feature is always disabled).
1 parent 6a8d3d5 commit 35584c7

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

crates/environ/src/component/translate.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ use crate::prelude::*;
33
use crate::ScopeVec;
44
use crate::{
55
EngineOrModuleTypeIndex, EntityIndex, ModuleEnvironment, ModuleInternedTypeIndex,
6-
ModuleTranslation, ModuleTypesBuilder, PrimaryMap, Tunables, TypeConvert, WasmHeapType,
7-
WasmResult, WasmValType,
6+
ModuleTranslation, ModuleTypesBuilder, PrimaryMap, TagIndex, Tunables, TypeConvert,
7+
WasmHeapType, WasmResult, WasmValType,
88
};
99
use anyhow::anyhow;
1010
use anyhow::{bail, Result};
@@ -321,6 +321,7 @@ enum LocalInitializer<'data> {
321321
AliasExportTable(ModuleInstanceIndex, &'data str),
322322
AliasExportGlobal(ModuleInstanceIndex, &'data str),
323323
AliasExportMemory(ModuleInstanceIndex, &'data str),
324+
AliasExportTag(ModuleInstanceIndex, &'data str),
324325
AliasComponentExport(ComponentInstanceIndex, &'data str),
325326
AliasModule(ClosedOverModule),
326327
AliasComponent(ClosedOverComponent),
@@ -1039,9 +1040,10 @@ impl<'a, 'data> Translator<'a, 'data> {
10391040
let index = GlobalIndex::from_u32(export.index);
10401041
EntityIndex::Global(index)
10411042
}
1042-
1043-
// doesn't get past validation
1044-
wasmparser::ExternalKind::Tag => unimplemented!("wasm exceptions"),
1043+
wasmparser::ExternalKind::Tag => {
1044+
let index = TagIndex::from_u32(export.index);
1045+
EntityIndex::Tag(index)
1046+
}
10451047
};
10461048
map.insert(export.name, idx);
10471049
}
@@ -1123,9 +1125,7 @@ impl<'a, 'data> Translator<'a, 'data> {
11231125
wasmparser::ExternalKind::Memory => LocalInitializer::AliasExportMemory(instance, name),
11241126
wasmparser::ExternalKind::Table => LocalInitializer::AliasExportTable(instance, name),
11251127
wasmparser::ExternalKind::Global => LocalInitializer::AliasExportGlobal(instance, name),
1126-
wasmparser::ExternalKind::Tag => {
1127-
unimplemented!("wasm exceptions");
1128-
}
1128+
wasmparser::ExternalKind::Tag => LocalInitializer::AliasExportTag(instance, name),
11291129
}
11301130
}
11311131

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ struct InlinerFrame<'a> {
204204
memories: PrimaryMap<MemoryIndex, dfg::CoreExport<EntityIndex>>,
205205
tables: PrimaryMap<TableIndex, dfg::CoreExport<EntityIndex>>,
206206
globals: PrimaryMap<GlobalIndex, dfg::CoreExport<EntityIndex>>,
207+
tags: PrimaryMap<GlobalIndex, dfg::CoreExport<EntityIndex>>,
207208
modules: PrimaryMap<ModuleIndex, ModuleDef<'a>>,
208209

209210
// component model index spaces
@@ -1164,6 +1165,15 @@ impl<'a> Inliner<'a> {
11641165
);
11651166
}
11661167

1168+
AliasExportTag(instance, name) => {
1169+
frame.tags.push(
1170+
match self.core_def_of_module_instance_export(frame, *instance, *name) {
1171+
dfg::CoreDef::Export(e) => e,
1172+
_ => unreachable!(),
1173+
},
1174+
);
1175+
}
1176+
11671177
AliasComponentExport(instance, name) => {
11681178
match &frame.component_instances[*instance] {
11691179
// Aliasing an export from an imported instance means that
@@ -1480,6 +1490,7 @@ impl<'a> InlinerFrame<'a> {
14801490
memories: Default::default(),
14811491
tables: Default::default(),
14821492
globals: Default::default(),
1493+
tags: Default::default(),
14831494

14841495
component_instances: Default::default(),
14851496
component_funcs: Default::default(),

0 commit comments

Comments
 (0)