kobako 0.12.1 → 0.12.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.release-please-manifest.json +1 -1
  3. data/CHANGELOG.md +11 -0
  4. data/Cargo.lock +15 -2
  5. data/Cargo.toml +6 -2
  6. data/README.md +1 -1
  7. data/crates/kobako-runtime/CHANGELOG.md +8 -0
  8. data/crates/kobako-runtime/Cargo.toml +23 -0
  9. data/crates/kobako-runtime/README.md +34 -0
  10. data/crates/kobako-runtime/src/dispatch.rs +22 -0
  11. data/crates/kobako-runtime/src/error.rs +64 -0
  12. data/crates/kobako-runtime/src/lib.rs +16 -0
  13. data/crates/kobako-runtime/src/runtime.rs +50 -0
  14. data/crates/kobako-runtime/src/snapshot.rs +46 -0
  15. data/crates/kobako-runtime/src/yielder.rs +22 -0
  16. data/crates/kobako-wasmtime/CHANGELOG.md +8 -0
  17. data/crates/kobako-wasmtime/Cargo.toml +62 -0
  18. data/crates/kobako-wasmtime/README.md +32 -0
  19. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/ambient.rs +3 -3
  20. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/cache.rs +30 -41
  21. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/capture.rs +2 -2
  22. data/crates/kobako-wasmtime/src/config.rs +25 -0
  23. data/crates/kobako-wasmtime/src/dispatch.rs +110 -0
  24. data/crates/kobako-wasmtime/src/driver.rs +285 -0
  25. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/exports.rs +5 -6
  26. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/frames.rs +70 -82
  27. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/guest_mem.rs +38 -15
  28. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/instance_pre.rs +13 -21
  29. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/invocation.rs +54 -49
  30. data/crates/kobako-wasmtime/src/lib.rs +47 -0
  31. data/{ext/kobako/src/runtime → crates/kobako-wasmtime/src}/trap.rs +29 -35
  32. data/data/kobako.wasm +0 -0
  33. data/ext/kobako/Cargo.toml +9 -32
  34. data/ext/kobako/src/runtime/bridge.rs +150 -0
  35. data/ext/kobako/src/runtime/errors.rs +45 -13
  36. data/ext/kobako/src/runtime.rs +156 -406
  37. data/ext/kobako/src/snapshot.rs +27 -62
  38. data/lib/kobako/catalog/handles.rb +3 -3
  39. data/lib/kobako/catalog/namespaces.rb +4 -0
  40. data/lib/kobako/catalog/snippets.rb +4 -0
  41. data/lib/kobako/codec/encoder.rb +5 -1
  42. data/lib/kobako/codec/factory.rb +41 -13
  43. data/lib/kobako/codec/handle_walk.rb +4 -0
  44. data/lib/kobako/errors.rb +18 -16
  45. data/lib/kobako/sandbox.rb +20 -18
  46. data/lib/kobako/sandbox_options.rb +25 -9
  47. data/lib/kobako/snapshot.rb +7 -13
  48. data/lib/kobako/transport/dispatcher.rb +2 -2
  49. data/lib/kobako/transport/response.rb +14 -14
  50. data/lib/kobako/transport/run.rb +2 -6
  51. data/lib/kobako/transport/yield.rb +1 -1
  52. data/lib/kobako/transport/yielder.rb +2 -2
  53. data/lib/kobako/version.rb +1 -1
  54. data/release-please-config.json +48 -3
  55. data/sig/kobako/codec/factory.rbs +3 -0
  56. data/sig/kobako/errors.rbs +7 -14
  57. data/sig/kobako/runtime.rbs +8 -3
  58. data/sig/kobako/sandbox.rbs +2 -2
  59. data/sig/kobako/sandbox_options.rbs +4 -2
  60. data/sig/kobako/snapshot.rbs +0 -3
  61. data/sig/kobako/transport/dispatcher.rbs +1 -1
  62. data/sig/kobako/transport/run.rbs +2 -2
  63. data/sig/kobako/transport/yielder.rbs +2 -2
  64. data/sig/kobako/transport.rbs +8 -0
  65. metadata +27 -12
  66. data/ext/kobako/src/runtime/config.rs +0 -25
  67. data/ext/kobako/src/runtime/dispatch.rs +0 -211
@@ -11,6 +11,8 @@
11
11
  use magnus::value::Lazy;
12
12
  use magnus::{prelude::*, Error as MagnusError, ExceptionClass, RModule, Ruby};
13
13
 
14
+ use kobako_runtime::error::{Error, SetupError, Trap};
15
+
14
16
  /// Resolve `Kobako::<name>` as an `ExceptionClass` — the shared body of
15
17
  /// every error-class `Lazy` below, which differ only in the constant
16
18
  /// name. The constants are guaranteed present by the time any of these
@@ -22,22 +24,20 @@ fn kobako_error_class(ruby: &Ruby, name: &str) -> ExceptionClass {
22
24
  kobako.const_get(name).unwrap()
23
25
  }
24
26
 
25
- pub(crate) static SETUP_ERROR: Lazy<ExceptionClass> =
26
- Lazy::new(|ruby| kobako_error_class(ruby, "SetupError"));
27
+ static SETUP_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| kobako_error_class(ruby, "SetupError"));
27
28
 
28
- pub(crate) static MODULE_NOT_BUILT_ERROR: Lazy<ExceptionClass> =
29
+ static MODULE_NOT_BUILT_ERROR: Lazy<ExceptionClass> =
29
30
  Lazy::new(|ruby| kobako_error_class(ruby, "ModuleNotBuiltError"));
30
31
 
31
- pub(crate) static TRAP_ERROR: Lazy<ExceptionClass> =
32
- Lazy::new(|ruby| kobako_error_class(ruby, "TrapError"));
32
+ static TRAP_ERROR: Lazy<ExceptionClass> = Lazy::new(|ruby| kobako_error_class(ruby, "TrapError"));
33
33
 
34
- pub(crate) static TIMEOUT_ERROR: Lazy<ExceptionClass> =
34
+ static TIMEOUT_ERROR: Lazy<ExceptionClass> =
35
35
  Lazy::new(|ruby| kobako_error_class(ruby, "TimeoutError"));
36
36
 
37
- pub(crate) static MEMORY_LIMIT_ERROR: Lazy<ExceptionClass> =
37
+ static MEMORY_LIMIT_ERROR: Lazy<ExceptionClass> =
38
38
  Lazy::new(|ruby| kobako_error_class(ruby, "MemoryLimitError"));
39
39
 
40
- pub(crate) static SANDBOX_ERROR: Lazy<ExceptionClass> =
40
+ static SANDBOX_ERROR: Lazy<ExceptionClass> =
41
41
  Lazy::new(|ruby| kobako_error_class(ruby, "SandboxError"));
42
42
 
43
43
  /// Build a `MagnusError` in `class` carrying `msg` — the shared body of
@@ -51,7 +51,7 @@ fn error_in(ruby: &Ruby, class: &Lazy<ExceptionClass>, msg: impl Into<String>) -
51
51
  /// invocation-time wasmtime engine failure that is not a configured-cap
52
52
  /// trap — missing exports, allocation faults, memory write/read failures.
53
53
  /// Construction-time setup failures use `setup_err`, not this.
54
- pub(crate) fn trap_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
54
+ pub(super) fn trap_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
55
55
  error_in(ruby, &TRAP_ERROR, msg)
56
56
  }
57
57
 
@@ -61,21 +61,21 @@ pub(crate) fn trap_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
61
61
  /// module, or engine / linker / instantiation setup failure. The
62
62
  /// `ModuleNotBuiltError` subclass (artifact absent) is
63
63
  /// raised through `MODULE_NOT_BUILT_ERROR` directly.
64
- pub(crate) fn setup_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
64
+ pub(super) fn setup_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
65
65
  error_in(ruby, &SETUP_ERROR, msg)
66
66
  }
67
67
 
68
68
  /// Construct a `Kobako::TimeoutError` magnus error. Surfaces the
69
69
  /// wall-clock cap path with the verb prefix added
70
70
  /// by `Kobako::Sandbox#invoke!`.
71
- pub(crate) fn timeout_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
71
+ fn timeout_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
72
72
  error_in(ruby, &TIMEOUT_ERROR, msg)
73
73
  }
74
74
 
75
75
  /// Construct a `Kobako::MemoryLimitError` magnus error. Surfaces the
76
76
  /// linear-memory cap path with the verb prefix
77
77
  /// added by `Kobako::Sandbox#invoke!`.
78
- pub(crate) fn memory_limit_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
78
+ fn memory_limit_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
79
79
  error_in(ruby, &MEMORY_LIMIT_ERROR, msg)
80
80
  }
81
81
 
@@ -85,6 +85,38 @@ pub(crate) fn memory_limit_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusErr
85
85
  /// envelope reservation failure (`__kobako_alloc` returns 0).
86
86
  /// The runtime is intact, so this must not be a
87
87
  /// `TrapError`: no discard-and-recreate recovery is owed to the caller.
88
- pub(crate) fn sandbox_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
88
+ fn sandbox_err(ruby: &Ruby, msg: impl Into<String>) -> MagnusError {
89
89
  error_in(ruby, &SANDBOX_ERROR, msg)
90
90
  }
91
+
92
+ /// Map a neutral `Trap` onto its `Kobako::TrapError`-family Ruby exception.
93
+ /// The boundary between the magnus-free run mechanics and the Ruby surface:
94
+ /// the run path classifies a fault into a `Trap`, and this is where it
95
+ /// becomes a raised exception.
96
+ pub(super) fn trap_to_magnus(ruby: &Ruby, trap: Trap) -> MagnusError {
97
+ match trap {
98
+ Trap::Timeout(msg) => timeout_err(ruby, msg),
99
+ Trap::MemoryLimit(msg) => memory_limit_err(ruby, msg),
100
+ Trap::Other(msg) => trap_err(ruby, msg),
101
+ }
102
+ }
103
+
104
+ /// Map a neutral `SetupError` onto the `Kobako::*` class the SPEC assigns
105
+ /// to each runtime state — artifact-absent, runtime-dead, runtime-intact.
106
+ pub(super) fn setup_to_magnus(ruby: &Ruby, err: SetupError) -> MagnusError {
107
+ match err {
108
+ SetupError::ModuleNotBuilt(msg) => error_in(ruby, &MODULE_NOT_BUILT_ERROR, msg),
109
+ SetupError::Dead(msg) => setup_err(ruby, msg),
110
+ SetupError::Intact(msg) => sandbox_err(ruby, msg),
111
+ }
112
+ }
113
+
114
+ /// Map either run-path channel onto its Ruby exception. The single
115
+ /// translation point the run-path entry methods funnel their `Result`
116
+ /// through.
117
+ pub(super) fn to_magnus(ruby: &Ruby, err: Error) -> MagnusError {
118
+ match err {
119
+ Error::Trap(trap) => trap_to_magnus(ruby, trap),
120
+ Error::Setup(err) => setup_to_magnus(ruby, err),
121
+ }
122
+ }