Repository: bytecodealliance/wasmtime
Pull request #7233 (2023-10-12 19:30:21)

remove logging from wit deps
I believe this was missed in the code review for #7029, it was introduced as an intermediate step in that PR but wasnt fully removed.

Also, the command extended world can now use `include wasi:cli/command;` which is a really nice improvement.

<!--
Please make sure you include the following information:

- If this work has been discussed elsewhere, please include a link to that
  conversation. If it was discussed in an issue, just mention "issue #...".

- Explain why this change is needed. If the details are in an issue already,
  this can be brief.

Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.html

Please ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->



Patch:
diff --git a/crates/c-api/include/wasmtime/async.h b/crates/c-api/include/wasmtime/async.h
index 3919dc3f1..955944c72 100644
--- a/crates/c-api/include/wasmtime/async.h
+++ b/crates/c-api/include/wasmtime/async.h
@@ -353,7 +353,7 @@ typedef struct {
  */
 WASM_API_EXTERN void wasmtime_config_host_stack_creator_set(
     wasm_config_t*,
-    wasmtime_memory_creator_t*);
+    wasmtime_stack_creator_t*);
 
 
 #ifdef __cplusplus
diff --git a/crates/c-api/include/wasmtime/config.h b/crates/c-api/include/wasmtime/config.h
index 38f1edc1b..38429f84b 100644
--- a/crates/c-api/include/wasmtime/config.h
+++ b/crates/c-api/include/wasmtime/config.h
@@ -460,6 +460,22 @@ WASM_API_EXTERN void wasmtime_config_host_memory_creator_set(
     wasm_config_t*,
     wasmtime_memory_creator_t*);
 
+/**
+ * \brief Configures whether copy-on-write memory-mapped data is used to initialize a linear memory.
+ *
+ * Initializing linear memory via a copy-on-write mapping can drastically improve instantiation costs 
+ * of a WebAssembly module because copying memory is deferred. Additionally if a page of memory is 
+ * only ever read from WebAssembly and never written too then the same underlying page of data will
+ * be reused between all instantiations of a module meaning that if a module is instantiated many
+ * times this can lower the overall memory required needed to run that module.
+ *
+ * This option defaults to true.
+ *
+ * For more information see the Rust documentation at
+ * https://docs.wasmtime.dev/api/wasmtime/struct.Config.html#method.memory_init_cow
+ */
+WASMTIME_CONFIG_PROP(void, memory_init_cow, bool)
+
 #ifdef __cplusplus
 }  // extern "C"
 #endif
diff --git a/crates/c-api/src/config.rs b/crates/c-api/src/config.rs
index bcf8acde6..201e05196 100644
--- a/crates/c-api/src/config.rs
+++ b/crates/c-api/src/config.rs
@@ -424,3 +424,8 @@ pub unsafe extern "C" fn wasmtime_config_host_memory_creator_set(
         new_memory: creator.new_memory,
     }));
 }
+
+#[no_mangle]
+pub extern "C" fn wasmtime_config_memory_init_cow_set(c: &mut wasm_config_t, enable: bool) {
+    c.config.memory_init_cow(enable);
+}
diff --git a/crates/wasi-http/wit/command-extended.wit b/crates/wasi-http/wit/command-extended.wit
index b4d08aed3..37e4fcb92 100644
--- a/crates/wasi-http/wit/command-extended.wit
+++ b/crates/wasi-http/wit/command-extended.wit
@@ -1,37 +1,6 @@
 // All of the same imports and exports available in the wasi:cli/command world
 // with addition of HTTP proxy related imports:
 world command-extended {
-  import wasi:clocks/wall-clock;
-  import wasi:clocks/monotonic-clock;
-  import wasi:clocks/timezone;
-  import wasi:filesystem/types;
-  import wasi:filesystem/preopens;
-  import wasi:sockets/instance-network;
-  import wasi:sockets/ip-name-lookup;
-  import wasi:sockets/network;
-  import wasi:sockets/tcp-create-socket;
-  import wasi:sockets/tcp;
-  import wasi:sockets/udp-create-socket;
-  import wasi:sockets/udp;
-  import wasi:random/random;
-  import wasi:random/insecure;
-  import wasi:random/insecure-seed;
-  import wasi:io/poll;
-  import wasi:io/streams;
-  import wasi:cli/environment;
-  import wasi:cli/exit;
-  import wasi:cli/stdin;
-  import wasi:cli/stdout;
-  import wasi:cli/stderr;
-  import wasi:cli/terminal-input;
-  import wasi:cli/terminal-output;
-  import wasi:cli/terminal-stdin;
-  import wasi:cli/terminal-stdout;
-  import wasi:cli/terminal-stderr;
-
-  // We should replace all others with `include self.command`
-  // as soon as the unioning of worlds is available:
-  // https://github.com/WebAssembly/component-model/issues/169
-  import wasi:logging/logging;
+  include wasi:cli/command;
   import wasi:http/outgoing-handler;
 }
diff --git a/crates/wasi-http/wit/deps/logging/logging.wit b/crates/wasi-http/wit/deps/logging/logging.wit
deleted file mode 100644
index da537e479..000000000
--- a/crates/wasi-http/wit/deps/logging/logging.wit
+++ /dev/null
@@ -1,37 +0,0 @@
-package wasi:logging;
-
-/// WASI Logging is a logging API intended to let users emit log messages with
-/// simple priority levels and context values.
-interface logging {
-    /// A log level, describing a kind of message.
-    enum level {
-       /// Describes messages about the values of variables and the flow of
-       /// control within a program.
-       trace,
-
-       /// Describes messages likely to be of interest to someone debugging a
-       /// program.
-       debug,
-
-       /// Describes messages likely to be of interest to someone monitoring a
-       /// program.
-       info,
-
-       /// Describes messages indicating hazardous situations.
-       warn,
-
-       /// Describes messages indicating serious errors.
-       error,
-
-       /// Describes messages indicating fatal errors.
-       critical,
-    }
-
-    /// Emit a log message.
-    ///
-    /// A log message has a `level` describing what kind of message is being
-    /// sent, a context, which is an uninterpreted string meant to help
-    /// consumers group similar messages, and a string containing the message
-    /// text.
-    log: func(level: level, context: string, message: string);
-}
diff --git a/crates/wasi-http/wit/deps/logging/world.wit b/crates/wasi-http/wit/deps/logging/world.wit
deleted file mode 100644
index ede628643..000000000
--- a/crates/wasi-http/wit/deps/logging/world.wit
+++ /dev/null
@@ -1,5 +0,0 @@
-package wasi:logging;
-
-world imports {
-    import logging;
-}
diff --git a/crates/wasi/wit/command-extended.wit b/crates/wasi/wit/command-extended.wit
index b4d08aed3..37e4fcb92 100644
--- a/crates/wasi/wit/command-extended.wit
+++ b/crates/wasi/wit/command-extended.wit
@@ -1,37 +1,6 @@
 // All of the same imports and exports available in the wasi:cli/command world
 // with addition of HTTP proxy related imports:
 world command-extended {
-  import wasi:clocks/wall-clock;
-  import wasi:clocks/monotonic-clock;
-  import wasi:clocks/timezone;
-  import wasi:filesystem/types;
-  import wasi:filesystem/preopens;
-  import wasi:sockets/instance-network;
-  import wasi:sockets/ip-name-lookup;
-  import wasi:sockets/network;
-  import wasi:sockets/tcp-create-socket;
-  import wasi:sockets/tcp;
-  import wasi:sockets/udp-create-socket;
-  import wasi:sockets/udp;
-  import wasi:random/random;
-  import wasi:random/insecure;
-  import wasi:random/insecure-seed;
-  import wasi:io/poll;
-  import wasi:io/streams;
-  import wasi:cli/environment;
-  import wasi:cli/exit;
-  import wasi:cli/stdin;
-  import wasi:cli/stdout;
-  import wasi:cli/stderr;
-  import wasi:cli/terminal-input;
-  import wasi:cli/terminal-output;
-  import wasi:cli/terminal-stdin;
-  import wasi:cli/terminal-stdout;
-  import wasi:cli/terminal-stderr;
-
-  // We should replace all others with `include self.command`
-  // as soon as the unioning of worlds is available:
-  // https://github.com/WebAssembly/component-model/issues/169
-  import wasi:logging/logging;
+  include wasi:cli/command;
   import wasi:http/outgoing-handler;
 }
diff --git a/crates/wasi/wit/deps/logging/logging.wit b/crates/wasi/wit/deps/logging/logging.wit
deleted file mode 100644
index da537e479..000000000
--- a/crates/wasi/wit/deps/logging/logging.wit
+++ /dev/null
@@ -1,37 +0,0 @@
-package wasi:logging;
-
-/// WASI Logging is a logging API intended to let users emit log messages with
-/// simple priority levels and context values.
-interface logging {
-    /// A log level, describing a kind of message.
-    enum level {
-       /// Describes messages about the values of variables and the flow of
-       /// control within a program.
-       trace,
-
-       /// Describes messages likely to be of interest to someone debugging a
-       /// program.
-       debug,
-
-       /// Describes messages likely to be of interest to someone monitoring a
-       /// program.
-       info,
-
-       /// Describes messages indicating hazardous situations.
-       warn,
-
-       /// Describes messages indicating serious errors.
-       error,
-
-       /// Describes messages indicating fatal errors.
-       critical,
-    }
-
-    /// Emit a log message.
-    ///
-    /// A log message has a `level` describing what kind of message is being
-    /// sent, a context, which is an uninterpreted string meant to help
-    /// consumers group similar messages, and a string containing the message
-    /// text.
-    log: func(level: level, context: string, message: string);
-}
diff --git a/crates/wasi/wit/deps/logging/world.wit b/crates/wasi/wit/deps/logging/world.wit
deleted file mode 100644
index ede628643..000000000
--- a/crates/wasi/wit/deps/logging/world.wit
+++ /dev/null
@@ -1,5 +0,0 @@
-package wasi:logging;
-
-world imports {
-    import logging;
-}


Test patch:
diff --git a/crates/test-programs/src/bin/cli_panic.rs b/crates/test-programs/src/bin/cli_panic.rs
deleted file mode 100644
index bf9d3b49e..000000000
--- a/crates/test-programs/src/bin/cli_panic.rs
+++ /dev/null
@@ -1,3 +0,0 @@
-fn main() {
-    panic!("idk!!!");
-}
diff --git a/crates/test-programs/src/bin/cli_stream_pollable_lifetimes.rs b/crates/test-programs/src/bin/cli_stream_pollable_lifetimes.rs
deleted file mode 100644
index 11fa0abc4..000000000
--- a/crates/test-programs/src/bin/cli_stream_pollable_lifetimes.rs
+++ /dev/null
@@ -1,29 +0,0 @@
-use test_programs::wasi::cli::environment;
-use test_programs::wasi::cli::stdin;
-use test_programs::wasi::io::poll;
-use test_programs::wasi::io::streams;
-
-fn main() {
-    let args = environment::get_arguments();
-    let args = &args[1..];
-
-    if args == &["correct"] {
-        let stdin: streams::InputStream = stdin::get_stdin();
-        let stdin_pollable = stdin.subscribe();
-        let ready = poll::poll_list(&[&stdin_pollable]);
-        assert_eq!(ready, &[0]);
-        drop(stdin_pollable);
-        drop(stdin);
-    } else if args == &["trap"] {
-        let stdin: streams::InputStream = stdin::get_stdin();
-        let stdin_pollable = stdin.subscribe();
-        let ready = poll::poll_list(&[&stdin_pollable]);
-        assert_eq!(ready, &[0]);
-        drop(stdin);
-        unreachable!(
-            "execution should have trapped in line above when stream dropped before pollable"
-        );
-    } else {
-        panic!("bad value for args: expected `[\"correct\"]` or `[\"trap\"]`, got {args:?}")
-    }
-}
diff --git a/crates/test-programs/src/bin/preview2_stream_pollable_correct.rs b/crates/test-programs/src/bin/preview2_stream_pollable_correct.rs
new file mode 100644
index 000000000..dfb155734
--- /dev/null
+++ b/crates/test-programs/src/bin/preview2_stream_pollable_correct.rs
@@ -0,0 +1,12 @@
+use test_programs::wasi::cli::stdin;
+use test_programs::wasi::io::poll;
+use test_programs::wasi::io::streams;
+
+fn main() {
+    let stdin: streams::InputStream = stdin::get_stdin();
+    let stdin_pollable = stdin.subscribe();
+    let ready = poll::poll_list(&[&stdin_pollable]);
+    assert_eq!(ready, &[0]);
+    drop(stdin_pollable);
+    drop(stdin);
+}
diff --git a/crates/test-programs/src/bin/preview2_stream_pollable_traps.rs b/crates/test-programs/src/bin/preview2_stream_pollable_traps.rs
new file mode 100644
index 000000000..13331fb02
--- /dev/null
+++ b/crates/test-programs/src/bin/preview2_stream_pollable_traps.rs
@@ -0,0 +1,12 @@
+use test_programs::wasi::cli::stdin;
+use test_programs::wasi::io::poll;
+use test_programs::wasi::io::streams;
+
+fn main() {
+    let stdin: streams::InputStream = stdin::get_stdin();
+    let stdin_pollable = stdin.subscribe();
+    let ready = poll::poll_list(&[&stdin_pollable]);
+    assert_eq!(ready, &[0]);
+    drop(stdin);
+    unreachable!("execution should have trapped in line above when stream dropped before pollable");
+}
diff --git a/crates/wasi/tests/all/async_.rs b/crates/wasi/tests/all/async_.rs
index c6e60d1e6..c1813476b 100644
--- a/crates/wasi/tests/all/async_.rs
+++ b/crates/wasi/tests/all/async_.rs
@@ -328,3 +328,19 @@ async fn preview2_udp_sample_application() {
 async fn preview2_tcp_connect() {
     run(PREVIEW2_TCP_CONNECT_COMPONENT, false).await.unwrap()
 }
+#[test_log::test(tokio::test(flavor = "multi_thread"))]
+async fn preview2_stream_pollable_correct() {
+    run(PREVIEW2_STREAM_POLLABLE_CORRECT_COMPONENT, false)
+        .await
+        .unwrap()
+}
+#[test_log::test(tokio::test(flavor = "multi_thread"))]
+async fn preview2_stream_pollable_traps() {
+    let e = run(PREVIEW2_STREAM_POLLABLE_TRAPS_COMPONENT, false)
+        .await
+        .unwrap_err();
+    assert_eq!(
+        format!("{}", e.source().expect("trap source")),
+        "entry still has children"
+    )
+}
diff --git a/crates/wasi/tests/all/sync.rs b/crates/wasi/tests/all/sync.rs
index c7e9da1d7..4347e01d9 100644
--- a/crates/wasi/tests/all/sync.rs
+++ b/crates/wasi/tests/all/sync.rs
@@ -269,3 +269,15 @@ fn preview2_udp_sample_application() {
 fn preview2_tcp_connect() {
     run(PREVIEW2_TCP_CONNECT_COMPONENT, false).unwrap()
 }
+#[test_log::test]
+fn preview2_stream_pollable_correct() {
+    run(PREVIEW2_STREAM_POLLABLE_CORRECT_COMPONENT, false).unwrap()
+}
+#[test_log::test]
+fn preview2_stream_pollable_traps() {
+    let e = run(PREVIEW2_STREAM_POLLABLE_TRAPS_COMPONENT, false).unwrap_err();
+    assert_eq!(
+        format!("{}", e.source().expect("trap source")),
+        "entry still has children"
+    )
+}
diff --git a/tests/all/cli_tests.rs b/tests/all/cli_tests.rs
index 93e19b64c..997738cdd 100644
--- a/tests/all/cli_tests.rs
+++ b/tests/all/cli_tests.rs
@@ -1026,29 +1026,6 @@ mod test_programs {
         Ok(())
     }
 
-    #[test]
-    fn cli_panic() -> Result<()> {
-        let output = get_wasmtime_command()?
-            .args(&[
-                "run",
-                "-Wcomponent-model",
-                CLI_PANIC_COMPONENT,
-                "diesel",
-                "the",
-                "cat",
-                "scratched",
-                "me",
-                "real",
-                "good",
-                "yesterday",
-            ])
-            .output()?;
-        assert!(!output.status.success());
-        let stderr = String::from_utf8_lossy(&output.stderr);
-        assert!(stderr.contains("idk!!!"));
-        Ok(())
-    }
-
     #[test]
     fn cli_args() -> Result<()> {
         run_wasmtime(&[
@@ -1182,6 +1159,8 @@ mod test_programs {
             .args(&["run", "-Wcomponent-model", CLI_EXIT_PANIC_COMPONENT])
             .output()?;
         assert!(!output.status.success());
+        let stderr = String::from_utf8_lossy(&output.stderr);
+        assert!(stderr.contains("Curiouser and curiouser!"));
         Ok(())
     }
 
@@ -1221,32 +1200,6 @@ mod test_programs {
         Ok(())
     }
 
-    #[test]
-    fn cli_stream_pollable_lifetimes() -> Result<()> {
-        // Test program has two modes, dispatching based on argument.
-        run_wasmtime(&[
-            "run",
-            "-Wcomponent-model",
-            CLI_STREAM_POLLABLE_LIFETIMES_COMPONENT,
-            "correct",
-        ])?;
-        let output = get_wasmtime_command()?
-            .args(&[
-                "run",
-                "-Wcomponent-model",
-                CLI_STREAM_POLLABLE_LIFETIMES_COMPONENT,
-                "trap",
-            ])
-            .output()?;
-        assert!(!output.status.success());
-        let stderr = String::from_utf8_lossy(&output.stderr);
-        assert!(
-            stderr.contains("entry still has children"),
-            "bad stderr: {stderr}"
-        );
-        Ok(())
-    }
-
     #[test]
     fn run_wasi_http_component() -> Result<()> {
         let output = super::run_wasmtime_for_output(