From f18a0939e24fa3ef8a7035efc2186e380580d002 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 22 Jul 2025 17:59:03 -0700 Subject: [PATCH] Add an `already-called` error to `run` for wasip3. Define a `run` error type and use it in the `run` function, to allow programs to report an error instead of trapping if their `run` function is called more than once. --- wit-0.3.0-draft/run.wit | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/wit-0.3.0-draft/run.wit b/wit-0.3.0-draft/run.wit index 6dd8b68..602ddca 100644 --- a/wit-0.3.0-draft/run.wit +++ b/wit-0.3.0-draft/run.wit @@ -1,6 +1,23 @@ @since(version = 0.3.0) interface run { - /// Run the program. - @since(version = 0.3.0) - run: func() -> result; + /// Run the program. + /// + /// This function is only meant to be called once per Wasm instance. If it + /// is called more, it will immediately fail with `error.already-called`. + /// + /// If a program wishes to exit with a specific exit status value, it should + /// use the `exit.exit-with-code` function to exit rather than returning + /// from `run`. + @since(version = 0.3.0) + run: func() -> result<_, error>; + + /// An error code returned by `run`. + @since(version = 0.3.0) + enum error { + /// The program did not complete successfully. + error, + + /// The `run` function has already been called in the callee's instance. + already-called + } }