From eef1758d190759e029c97f479cf406558bf20994 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 29 Jun 2022 09:05:40 -0500 Subject: [PATCH] Implement a first-class error for reexported component functions (#4348) Currently I don't know how we can reasonably implement this. Given all the signatures of how we call functions and how functions are called on the host there's no real feasible way that I know of to hook these two up "seamlessly". This means that a component which reexports an imported function can't be run in Wasmtime. One of the main reasons for this is that when calling a component function Wasmtime wants to lower arguments first and then have them lifted when the host is called. With a reexport though there's not actually anything to lower into so we'd sort of need something similar to a table on the side or maybe a linear memory and that seems like it'd get quite complicated quite quickly for not really all that much benefit. As-such for now this simply returns a first-class error (rather than the current panic) in situations like this. --- crates/environ/src/component/translate/inline.rs | 4 +++- tests/misc_testsuite/component-model/import.wast | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/misc_testsuite/component-model/import.wast diff --git a/crates/environ/src/component/translate/inline.rs b/crates/environ/src/component/translate/inline.rs index 0dc5f83122a5..e5dbf786cde0 100644 --- a/crates/environ/src/component/translate/inline.rs +++ b/crates/environ/src/component/translate/inline.rs @@ -141,7 +141,9 @@ pub(super) fn run( ComponentFuncDef::Lifted { ty, func, options } => { Export::LiftedFunction { ty, func, options } } - ComponentFuncDef::Import(_) => unimplemented!("reexporting a function import"), + ComponentFuncDef::Import(_) => { + bail!("component export `{name}` is a reexport of an imported function which is not implemented") + } }, ComponentItemDef::Instance(_) => unimplemented!("exporting an instance to the host"), diff --git a/tests/misc_testsuite/component-model/import.wast b/tests/misc_testsuite/component-model/import.wast new file mode 100644 index 000000000000..4633ba26150e --- /dev/null +++ b/tests/misc_testsuite/component-model/import.wast @@ -0,0 +1,5 @@ +(assert_invalid + (component + (import "host-return-two" (func $f (result u32))) + (export "x" (func $f))) + "component export `x` is a reexport of an imported function which is not implemented")