wardite 1.0.0 → 1.2.0

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +9 -1
  3. data/README.md +65 -7
  4. data/Steepfile +1 -0
  5. data/assets/wardite.svg +12 -0
  6. data/benchmark/count_ruby_wasm_functions.rb +37 -0
  7. data/benchmark/measure_mir_cache_restore.rb +59 -0
  8. data/benchmark/measure_mir_cache_verify.rb +58 -0
  9. data/benchmark/measure_ruby_wasm_cache_hit.rb +59 -0
  10. data/benchmark/measure_ruby_wasm_startup.rb +43 -0
  11. data/benchmark/results/efflorescence-mir2-cache-integrity.json +390 -0
  12. data/benchmark/results/efflorescence-mir2-function-restore.json +480 -0
  13. data/benchmark/results/efflorescence-unboxed-globals.json +3451 -0
  14. data/docs/adr/0007-efflorescence-ruby-wasm-phase1.md +75 -0
  15. data/docs/adr/0008-efflorescence-ruby-wasm-phase2.md +75 -0
  16. data/docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md +77 -0
  17. data/docs/adr/0010-efflorescence-mir2-cache-function-restore.md +80 -0
  18. data/docs/adr/0011-efflorescence-unboxed-globals.md +89 -0
  19. data/docs/adr/0012-efflorescence-startup-snapshot.md +173 -0
  20. data/docs/adr/0013-efflorescence-frame-acquisition.md +114 -0
  21. data/docs/efflorescence-generated-c-guards.md +5 -0
  22. data/docs/efflorescence-mir2-cache.md +152 -0
  23. data/docs/efflorescence-ruby-wasm-phase1.md +90 -0
  24. data/docs/efflorescence-spinel-linear-memory.md +74 -0
  25. data/docs/efflorescence-startup-snapshot.md +60 -0
  26. data/docs/efflorescence-unboxed-globals.md +61 -0
  27. data/lib/wardite/alu_f32.generated.rb +10 -2
  28. data/lib/wardite/alu_f64.generated.rb +10 -2
  29. data/lib/wardite/alu_i32.generated.rb +40 -8
  30. data/lib/wardite/alu_i64.generated.rb +55 -11
  31. data/lib/wardite/cli/cli.rb +58 -6
  32. data/lib/wardite/efflorescence/ir.rb +26 -4
  33. data/lib/wardite/efflorescence/mir_cache.rb +749 -0
  34. data/lib/wardite/efflorescence/register_validation.rb +128 -56
  35. data/lib/wardite/efflorescence/snapshot.rb +232 -0
  36. data/lib/wardite/efflorescence/store_access.rb +103 -8
  37. data/lib/wardite/efflorescence/translator.rb +10 -3
  38. data/lib/wardite/efflorescence/vm.rb +203 -38
  39. data/lib/wardite/efflorescence/wasi.rb +0 -56
  40. data/lib/wardite/efflorescence.rb +6 -0
  41. data/lib/wardite/load.rb +109 -24
  42. data/lib/wardite/version.rb +1 -1
  43. data/lib/wardite/wasi/spinel.rb +41 -0
  44. data/lib/wardite/wasi.rb +483 -268
  45. data/lib/wardite.rb +218 -70
  46. data/scripts/build_spinel_zig.rb +121 -0
  47. data/scripts/gen_alu.rb +55 -11
  48. data/scripts/verify_ruby_wasm.rb +70 -0
  49. data/sig/generated/wardite/cli/cli.rbs +15 -0
  50. data/sig/generated/wardite/efflorescence/ir.rbs +12 -2
  51. data/sig/generated/wardite/efflorescence/mir_cache.rbs +263 -0
  52. data/sig/generated/wardite/efflorescence/register_validation.rbs +31 -3
  53. data/sig/generated/wardite/efflorescence/snapshot.rbs +84 -0
  54. data/sig/generated/wardite/efflorescence/store_access.rbs +13 -2
  55. data/sig/generated/wardite/efflorescence/translator.rbs +5 -1
  56. data/sig/generated/wardite/efflorescence/vm.rbs +68 -7
  57. data/sig/generated/wardite/efflorescence/wasi.rbs +0 -13
  58. data/sig/generated/wardite/load.rbs +33 -5
  59. data/sig/generated/wardite/wasi/spinel.rbs +15 -0
  60. data/sig/generated/wardite/wasi.rbs +111 -4
  61. data/sig/generated/wardite.rbs +67 -3
  62. data/sig/io_buffer.rbs +7 -0
  63. data/sig/mir_cache_stdlib.rbs +5 -0
  64. metadata +32 -1
@@ -7,16 +7,36 @@ module Wardite
7
7
 
8
8
  attr_reader ir: Wardite::Efflorescence::IR
9
9
 
10
- attr_reader semantic_ir: Wardite::Efflorescence::IR
10
+ attr_reader metrics: Wardite::Efflorescence::Metrics
11
11
 
12
- attr_reader optimized_ir: Wardite::Efflorescence::IR
12
+ attr_reader mir_cache_hit: bool
13
13
 
14
- attr_reader metrics: Wardite::Efflorescence::Metrics
14
+ attr_reader mir_cache: Wardite::Efflorescence::MIRCache?
15
+
16
+ # Records a startup snapshot before the first WASI call outside its allowlist.
17
+ attr_accessor snapshot: Wardite::Efflorescence::Snapshot?
18
+
19
+ @global_bits: Array[Integer]
20
+
21
+ @optimized_ir: Wardite::Efflorescence::IR?
22
+
23
+ @semantic_ir: Wardite::Efflorescence::IR?
15
24
 
16
25
  # @rbs instance: Wardite::Instance
17
26
  # @rbs disabled_optimizations: Array[Symbol]
18
27
  # @rbs profile: bool
19
- def initialize: (Wardite::Instance instance, ?disabled_optimizations: Array[Symbol], ?profile: bool) -> untyped
28
+ # @rbs mir_cache: Wardite::Efflorescence::MIRCache?
29
+ # @rbs cached_functions: Array[Function]?
30
+ # @rbs cache_checked: bool
31
+ def initialize: (Wardite::Instance instance, ?disabled_optimizations: Array[Symbol], ?profile: bool, ?mir_cache: Wardite::Efflorescence::MIRCache?, ?cached_functions: Array[Function]?, ?cache_checked: bool) -> untyped
32
+
33
+ # A caller explicitly inspecting a cache hit can still request the
34
+ # intermediate forms. Execution continues to use the restored MIR2.
35
+ # @rbs return: Wardite::Efflorescence::IR
36
+ def semantic_ir: () -> Wardite::Efflorescence::IR
37
+
38
+ # @rbs return: Wardite::Efflorescence::IR
39
+ def optimized_ir: () -> Wardite::Efflorescence::IR
20
40
 
21
41
  # @rbs name: String|Symbol
22
42
  # @rbs return: bool
@@ -47,8 +67,23 @@ module Wardite
47
67
  # @rbs return: String
48
68
  def dump_mir: () -> String
49
69
 
70
+ # Continue a public call restored from a startup snapshot. Each frame
71
+ # resumes at its saved pc: the host call for the top, a return for others.
72
+ # @rbs saved: Array[Wardite::Efflorescence::SavedFrame]
73
+ # @rbs return: void
74
+ def resume: (Array[Wardite::Efflorescence::SavedFrame] saved) -> void
75
+
50
76
  private
51
77
 
78
+ # @rbs translator: Wardite::Efflorescence::Translator
79
+ # @rbs linked: Wardite::Efflorescence::IR
80
+ # @rbs profile: bool
81
+ # @rbs return: Wardite::Efflorescence::IR
82
+ def build_mir: (Wardite::Efflorescence::Translator translator, Wardite::Efflorescence::IR linked, bool profile) -> Wardite::Efflorescence::IR
83
+
84
+ # @rbs return: void
85
+ def restore_inspection_ir: () -> void
86
+
52
87
  # @rbs name: String|Symbol
53
88
  # @rbs return: Wardite::Efflorescence::FunctionEntry
54
89
  def export_entry: (String | Symbol name) -> Wardite::Efflorescence::FunctionEntry
@@ -107,12 +142,27 @@ module Wardite
107
142
  # @rbs return: Wardite::Efflorescence::FramePool
108
143
  def pool_at: (Array[Wardite::Efflorescence::FramePool] pools, Integer index) -> Wardite::Efflorescence::FramePool
109
144
 
145
+ # Update in place so a suspended execute_flat retains the same array
146
+ # across a host call, including a reentrant call on this VM.
147
+ # @rbs return: void
148
+ def read_globals: () -> void
149
+
150
+ # @rbs return: void
151
+ def write_globals: () -> void
152
+
110
153
  # @rbs host_index: Integer
111
154
  # @rbs arguments: Array[Integer]
112
155
  # @rbs metrics: Wardite::Efflorescence::Metrics
156
+ # @rbs sources: Array[Integer]?
113
157
  # @rbs return: Integer?
158
+ def invoke_host_with_globals: (Integer host_index, Array[Integer] arguments, Wardite::Efflorescence::Metrics metrics, Array[Integer]? sources) -> Integer?
159
+
160
+ # @rbs host_index: Integer
161
+ # @rbs arguments: Array[Integer]
162
+ # @rbs metrics: Wardite::Efflorescence::Metrics
114
163
  # @rbs sources: Array[Integer]?
115
- def invoke_host: (Integer host_index, Array[Integer] arguments, Wardite::Efflorescence::Metrics metrics, ?Array[Integer]? sources) -> Integer?
164
+ # @rbs return: Integer?
165
+ def invoke_host: (Integer host_index, Array[Integer] arguments, Wardite::Efflorescence::Metrics metrics, Array[Integer]? sources) -> Integer?
116
166
 
117
167
  # @rbs host: Wardite::Efflorescence::HostFunction
118
168
  # @rbs arguments: Array[Integer]
@@ -120,13 +170,24 @@ module Wardite
120
170
  # @rbs return: Integer?
121
171
  def invoke_typed_host: (Wardite::Efflorescence::HostFunction host, Array[Integer] arguments, Array[Integer]? sources) -> Integer?
122
172
 
123
- # Each public entry owns its frames, pools and counters, including when a
124
- # host callback re-enters the VM. Store mutations are shared immediately.
173
+ # Each public or start entry owns its frames, pools and counters. Host
174
+ # calls synchronize globals before a callback can re-enter the VM.
125
175
  # @rbs entry: Wardite::Efflorescence::FunctionEntry
126
176
  # @rbs arguments: Array[Integer]
127
177
  # @rbs return: Integer?
128
178
  def execute: (Wardite::Efflorescence::FunctionEntry entry, Array[Integer] arguments) -> Integer?
129
179
 
180
+ # @rbs return: Array[Wardite::Efflorescence::FramePool]
181
+ def new_pools: () -> Array[Wardite::Efflorescence::FramePool]
182
+
183
+ # Globals live in @global_bits while frames run. A restored snapshot
184
+ # writes the Store first, so both public calls and resume read it here.
185
+ # @rbs pools: Array[Wardite::Efflorescence::FramePool]
186
+ # @rbs active_frames: Array[Wardite::Efflorescence::Frame]
187
+ # @rbs root_entries: Integer
188
+ # @rbs return: Integer
189
+ def run_frames: (Array[Wardite::Efflorescence::FramePool] pools, Array[Wardite::Efflorescence::Frame] active_frames, Integer root_entries) -> Integer
190
+
130
191
  # @rbs frame: Wardite::Efflorescence::Frame
131
192
  # @rbs site: Wardite::Efflorescence::DynamicCallSite
132
193
  # @rbs host_index: Integer
@@ -29,19 +29,6 @@ module Wardite
29
29
  # @rbs sources: Array[Integer]?
30
30
  # @rbs return: bot
31
31
  def proc_exit_from_registers: (untyped _store, Array[Integer] values, Array[Integer]? sources) -> bot
32
-
33
- # @rbs store: Wardite::Store
34
- # @rbs fd: Integer
35
- # @rbs iovs: Integer
36
- # @rbs count: Integer
37
- # @rbs written_at: Integer
38
- # @rbs return: Integer
39
- def fd_write_i32: (Wardite::Store store, Integer fd, Integer iovs, Integer count, Integer written_at) -> Integer
40
-
41
- # @rbs data: String
42
- # @rbs iov: Integer
43
- # @rbs return: String?
44
- def iovec_payload: (String data, Integer iov) -> String?
45
32
  end
46
33
  end
47
34
  end
@@ -97,11 +97,33 @@ module Wardite
97
97
 
98
98
  attr_accessor locals_type: Array[Symbol]
99
99
 
100
- attr_accessor body: Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
100
+ attr_writer instruction_bytes: String?
101
+
102
+ attr_writer type_section: TypeSection?
101
103
 
102
104
  # @rbs &blk: (CodeBody) -> void
103
105
  # @rbs return: void
104
106
  def initialize: () { (CodeBody) -> void } -> void
107
+
108
+ # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
109
+ def body: () -> Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]]
110
+
111
+ # @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
112
+ # @rbs return: void
113
+ def body=: (Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]] instructions) -> void
114
+
115
+ # @rbs types: TypeSection?
116
+ # @rbs stack: bool
117
+ # @rbs return: void
118
+ def check_features: (TypeSection? types, bool stack) -> void
119
+
120
+ private
121
+
122
+ # @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
123
+ # @rbs types: TypeSection?
124
+ # @rbs stack: bool
125
+ # @rbs return: void
126
+ def check_instructions: (Array[[ Symbol, Symbol, Array[operandItem], Integer?, Integer? ]] instructions, TypeSection? types, bool stack) -> void
105
127
  end
106
128
 
107
129
  attr_accessor func_codes: Array[CodeBody]
@@ -188,14 +210,18 @@ module Wardite
188
210
  # @rbs engine: Symbol
189
211
  # @rbs disabled_optimizations: Array[Symbol]
190
212
  # @rbs mir_profile: bool
213
+ # @rbs mir_cache: String?
214
+ # @rbs mir_cache_verify: Symbol
215
+ # @rbs mir_cache_eager: bool
191
216
  # @rbs return: Instance
192
- def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, wasmModuleSrc], ?enable_wasi: boolish, ?engine: Symbol, ?disabled_optimizations: Array[Symbol], ?mir_profile: bool) -> Instance
217
+ def self.load_from_buffer: (File | StringIO buf, ?import_object: Hash[Symbol, wasmModuleSrc], ?enable_wasi: boolish, ?engine: Symbol, ?disabled_optimizations: Array[Symbol], ?mir_profile: bool, ?mir_cache: String?, ?mir_cache_verify: Symbol, ?mir_cache_eager: bool) -> Instance
193
218
 
194
219
  # @rbs return: Integer
195
220
  def self.preamble: () -> Integer
196
221
 
222
+ # @rbs defer_code: bool
197
223
  # @rbs return: Array[Section]
198
- def self.sections: () -> Array[Section]
224
+ def self.sections: (?bool defer_code) -> Array[Section]
199
225
 
200
226
  # @rbs return: TypeSection
201
227
  def self.type_section: () -> TypeSection
@@ -224,12 +250,14 @@ module Wardite
224
250
  # @rbs return: TableSection
225
251
  def self.table_section: () -> TableSection
226
252
 
253
+ # @rbs defer_code: bool
227
254
  # @rbs return: CodeSection
228
- def self.code_section: () -> CodeSection
255
+ def self.code_section: (?bool defer_code) -> CodeSection
229
256
 
230
257
  # @rbs sbuf: StringIO
258
+ # @rbs defer_code: bool
231
259
  # @rbs return: CodeSection::CodeBody
232
- def self.read_function_body: (StringIO sbuf) -> CodeSection::CodeBody
260
+ def self.read_function_body: (StringIO sbuf, ?bool defer_code) -> CodeSection::CodeBody
233
261
 
234
262
  # @rbs buf: StringIO
235
263
  # @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
@@ -0,0 +1,15 @@
1
+ # Generated from lib/wardite/wasi/spinel.rb with RBS::Inline
2
+
3
+ module Wardite
4
+ module Wasi
5
+ module Native
6
+ def self.ffi_source: (String) -> void
7
+
8
+ def self.ffi_func: (Symbol, Array[Symbol], Symbol) -> void
9
+
10
+ def self.wardite_wasi_getfl: (Integer) -> Integer
11
+
12
+ def self.wardite_wasi_errno: (Integer) -> Integer
13
+ end
14
+ end
15
+ end
@@ -6,6 +6,19 @@ module Wardite
6
6
 
7
7
  include WasmModule
8
8
 
9
+ # Preview 1 imports return errno (i32), except for proc_exit.
10
+ IMPORT_PARAMETERS: Hash[Symbol, Array[Symbol]]
11
+
12
+ # @rbs name: Symbol
13
+ # @rbs parameters: Array[Symbol]
14
+ # @rbs results: Array[Symbol]
15
+ # @rbs return: void
16
+ def validate_import: (Symbol name, Array[Symbol] parameters, Array[Symbol] results) -> void
17
+
18
+ # @rbs name: Symbol
19
+ # @rbs return: _WasmCallable
20
+ def callable: (Symbol name) -> _WasmCallable
21
+
9
22
  attr_accessor fd_table: Hash[Integer, IO | File | ::Wardite::Wasi::PreopenedDir]
10
23
 
11
24
  attr_accessor fd_count: Integer
@@ -67,8 +80,35 @@ module Wardite
67
80
 
68
81
  # @rbs store: Store
69
82
  # @rbs args: Array[wasmValue]
70
- # @rbs return: Object
71
- def clock_time_get: (Store store, Array[wasmValue] args) -> Object
83
+ # @rbs return: Integer
84
+ def clock_res_get: (Store store, Array[wasmValue] args) -> Integer
85
+
86
+ # @rbs store: Store
87
+ # @rbs args: Array[wasmValue]
88
+ # @rbs return: Integer
89
+ def clock_time_get: (Store store, Array[wasmValue] args) -> Integer
90
+
91
+ # These imports can be linked, but their operations are not implemented.
92
+ # @rbs (Store, Array[wasmValue]) -> Integer
93
+ def fd_advise: (Store, Array[wasmValue]) -> Integer
94
+
95
+ alias fd_datasync fd_advise
96
+
97
+ alias fd_fdstat_set_flags fd_advise
98
+
99
+ alias fd_filestat_set_size fd_advise
100
+
101
+ alias fd_pread fd_advise
102
+
103
+ alias fd_pwrite fd_advise
104
+
105
+ alias fd_renumber fd_advise
106
+
107
+ alias fd_seek fd_advise
108
+
109
+ alias fd_sync fd_advise
110
+
111
+ alias poll_oneoff fd_advise
72
112
 
73
113
  # @rbs store: Store
74
114
  # @rbs args: Array[wasmValue]
@@ -174,10 +214,77 @@ module Wardite
174
214
  # @rbs return: Object
175
215
  def random_get: (Store store, Array[wasmValue] args) -> Object
176
216
 
217
+ # Everything an allowed call before a startup snapshot can observe:
218
+ # arguments, environment, and the kind of every open descriptor.
219
+ # @rbs return: String
220
+ def snapshot_identity: () -> String
221
+
222
+ # @rbs file: IO|File|::Wardite::Wasi::PreopenedDir
223
+ # @rbs return: [Integer, Integer]?
224
+ def fd_kind: (IO | File | ::Wardite::Wasi::PreopenedDir file) -> [ Integer, Integer ]?
225
+
177
226
  private
178
227
 
179
- # @rbs buf: String|nil
228
+ # @rbs store: Wardite::Store
229
+ # @rbs fd: Integer
230
+ # @rbs iovs: Integer
231
+ # @rbs count: Integer
232
+ # @rbs written_at: Integer
233
+ # @rbs return: Integer
234
+ def fd_write_i32: (Wardite::Store store, Integer fd, Integer iovs, Integer count, Integer written_at) -> Integer
235
+
236
+ # @rbs memory: Wardite::Memory
237
+ # @rbs iov: Integer
238
+ # @rbs return: String?
239
+ def iovec_payload: (Wardite::Memory memory, Integer iov) -> String?
240
+
241
+ # Bind the boxed host call to known methods when compiling with Spinel.
242
+ # @rbs name: Symbol
243
+ # @rbs store: Store
244
+ # @rbs args: Array[wasmValue]
245
+ # @rbs return: wasmFuncReturn
246
+ def dispatch_native_import: (Symbol name, Store store, Array[wasmValue] args) -> wasmFuncReturn
247
+
248
+ # @rbs fd: Integer
249
+ # @rbs path: String
250
+ # @rbs return: String | Integer
251
+ def directory_path: (Integer fd, String path) -> (String | Integer)
252
+
253
+ # @rbs error: SystemCallError
254
+ # @rbs return: Integer
255
+ def filesystem_errno: (SystemCallError error) -> Integer
256
+
257
+ # @rbs stat: File::Stat
258
+ # @rbs return: String
259
+ def filestat_bytes: (File::Stat stat) -> String
260
+
261
+ # @rbs return: Array[String]
262
+ def environment_entries: () -> Array[String]
263
+
264
+ # @rbs store: Store
265
+ # @rbs args: Array[wasmValue]
266
+ # @rbs count: Integer
267
+ # @rbs length: Integer
268
+ # @rbs return: Integer
269
+ def write_guest_sizes: (Store store, Array[wasmValue] args, Integer count, Integer length) -> Integer
270
+
271
+ # @rbs store: Store
272
+ # @rbs args: Array[wasmValue]
273
+ # @rbs entries: Array[String]
274
+ # @rbs return: Integer
275
+ def write_guest_strings: (Store store, Array[wasmValue] args, Array[String] entries) -> Integer
276
+
277
+ # @rbs store: Store
278
+ # @rbs offset: Integer
279
+ # @rbs length: Integer
280
+ # @rbs return: String?
281
+ def guest_path: (Store store, Integer offset, Integer length) -> String?
282
+
283
+ # @rbs store: Store
284
+ # @rbs clock_id: Integer
285
+ # @rbs offset: Integer
286
+ # @rbs resolution: bool
180
287
  # @rbs return: Integer
181
- def unpack_le_int: (String | nil buf) -> Integer
288
+ def write_clock: (Store store, Integer clock_id, Integer offset, resolution: bool) -> Integer
182
289
  end
183
290
  end
@@ -30,13 +30,18 @@ module Wardite
30
30
  # @rbs engine: Symbol
31
31
  # @rbs disabled_optimizations: Array[Symbol]
32
32
  # @rbs mir_profile: bool
33
+ # @rbs mir_cache: Efflorescence::MIRCache?
33
34
  # @rbs &blk: (Instance) -> void
34
- def initialize: (Hash[Symbol, wasmModuleSrc] import_object, ?engine: Symbol, ?disabled_optimizations: Array[Symbol], ?mir_profile: bool) { (Instance) -> void } -> untyped
35
+ def initialize: (Hash[Symbol, wasmModuleSrc] import_object, ?engine: Symbol, ?disabled_optimizations: Array[Symbol], ?mir_profile: bool, ?mir_cache: Efflorescence::MIRCache?) { (Instance) -> void } -> untyped
35
36
 
36
37
  # Run before allocating Store/Exports or executing a start function.
37
38
  # @rbs engine: Symbol
38
39
  # @rbs return: void
39
- def check_engine_features: (Symbol engine) -> void
40
+ def check_module_features: (Symbol engine) -> void
41
+
42
+ # @rbs &block: (Array[Symbol], Array[Symbol], CodeSection::CodeBody) -> void
43
+ # @rbs return: void
44
+ def each_defined_function: () { (Array[Symbol], Array[Symbol], CodeSection::CodeBody) -> void } -> void
40
45
 
41
46
  # Validate active segments before shared initialization can mutate memory.
42
47
  # @rbs return: void
@@ -250,7 +255,15 @@ module Wardite
250
255
  end
251
256
 
252
257
  class Memory
253
- attr_accessor data: String
258
+ PAGE_SIZE: Integer
259
+
260
+ MAX_PAGES: Integer
261
+
262
+ @storage: IO::Buffer?
263
+
264
+ @buffer: IO::Buffer?
265
+
266
+ @data: String?
254
267
 
255
268
  attr_accessor current: Integer
256
269
 
@@ -261,11 +274,62 @@ module Wardite
261
274
  # @rbs return: void
262
275
  def initialize: (Integer min, Integer | nil max) -> void
263
276
 
277
+ # The CRuby host API retains the mutable backing String.
278
+ # @rbs return: String
279
+ def data: () -> String
280
+
281
+ # @rbs value: String
282
+ # @rbs return: String
283
+ def data=: (String value) -> String
284
+
285
+ # The Spinel host API exposes only the current Wasm bytes. Reacquire it
286
+ # after any guest call that can grow memory.
287
+ # @rbs return: IO::Buffer
288
+ def buffer: () -> IO::Buffer
289
+
290
+ # @rbs return: Integer
291
+ def bytesize: () -> Integer
292
+
293
+ # @rbs offset: Integer
294
+ # @rbs length: Integer
295
+ # @rbs return: bool
296
+ def range?: (Integer offset, Integer length) -> bool
297
+
298
+ # @rbs offset: Integer
299
+ # @rbs length: Integer
300
+ # @rbs return: String
301
+ def read_bytes: (Integer offset, Integer length) -> String
302
+
303
+ # @rbs offset: Integer
304
+ # @rbs return: Integer
305
+ def read_u32: (Integer offset) -> Integer
306
+
307
+ # @rbs offset: Integer
308
+ # @rbs bytes: String
309
+ # @rbs return: void
310
+ def write_bytes: (Integer offset, String bytes) -> void
311
+
264
312
  # @rbs delta: Integer
265
313
  # @rbs return: Integer
266
314
  def grow: (Integer delta) -> Integer
267
315
 
268
316
  def inspect: () -> untyped
317
+
318
+ private
319
+
320
+ # @rbs pages: Integer
321
+ # @rbs limit: Integer
322
+ # @rbs return: bool
323
+ def grow_buffer: (Integer pages, Integer limit) -> bool
324
+
325
+ # @rbs replacement: IO::Buffer
326
+ # @rbs size: Integer
327
+ # @rbs return: void
328
+ def replace_storage: (IO::Buffer replacement, Integer size) -> void
329
+
330
+ # @rbs pages: Integer
331
+ # @rbs return: IO::Buffer?
332
+ def allocate_storage: (Integer pages) -> IO::Buffer?
269
333
  end
270
334
 
271
335
  class Table
data/sig/io_buffer.rbs ADDED
@@ -0,0 +1,7 @@
1
+ class IO
2
+ class Buffer
3
+ # The core signature currently omits the block form documented by Ruby.
4
+ def self.for: [Result] (String) { (Buffer) -> Result } -> Result
5
+ | ...
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Digest
2
+ class SHA256
3
+ def self.digest: (String) -> String
4
+ end
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wardite
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Uchio Kondo
@@ -22,6 +22,7 @@ files:
22
22
  - README.md
23
23
  - Rakefile
24
24
  - Steepfile
25
+ - assets/wardite.svg
25
26
  - benchmark/README.md
26
27
  - benchmark/build_call_profile.rb
27
28
  - benchmark/call_cost_worker.rb
@@ -30,6 +31,7 @@ files:
30
31
  - benchmark/compare_dispatch.rb
31
32
  - benchmark/compare_engines.rb
32
33
  - benchmark/compare_optimizations.rb
34
+ - benchmark/count_ruby_wasm_functions.rb
33
35
  - benchmark/engine_phases.rb
34
36
  - benchmark/figures/README.md
35
37
  - benchmark/figures/plot_spinel_comparison.py
@@ -51,6 +53,10 @@ files:
51
53
  - benchmark/measure_m3_calls.rb
52
54
  - benchmark/measure_m4.rb
53
55
  - benchmark/measure_m5_boundary.rb
56
+ - benchmark/measure_mir_cache_restore.rb
57
+ - benchmark/measure_mir_cache_verify.rb
58
+ - benchmark/measure_ruby_wasm_cache_hit.rb
59
+ - benchmark/measure_ruby_wasm_startup.rb
54
60
  - benchmark/measure_wasi_write.rb
55
61
  - benchmark/optimization_worker.rb
56
62
  - benchmark/results/call_arities_exploratory_2026-11-04.json
@@ -68,6 +74,9 @@ files:
68
74
  - benchmark/results/efflorescence-m2-i32-cruby.json
69
75
  - benchmark/results/efflorescence-m2-i32-spinel.json
70
76
  - benchmark/results/efflorescence-m2-memory.json
77
+ - benchmark/results/efflorescence-mir2-cache-integrity.json
78
+ - benchmark/results/efflorescence-mir2-function-restore.json
79
+ - benchmark/results/efflorescence-unboxed-globals.json
71
80
  - benchmark/results/generated_guards_exploratory_2026-11-04.json
72
81
  - benchmark/results/generated_guards_profile_2026-11-04.json
73
82
  - benchmark/results/generated_guards_spinel_2026-11-04.json
@@ -96,6 +105,13 @@ files:
96
105
  - docs/adr/0004-efflorescence-m4-i64.md
97
106
  - docs/adr/0005-efflorescence-m5-floating-point.md
98
107
  - docs/adr/0006-efflorescence-m6-coverage-parity.md
108
+ - docs/adr/0007-efflorescence-ruby-wasm-phase1.md
109
+ - docs/adr/0008-efflorescence-ruby-wasm-phase2.md
110
+ - docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md
111
+ - docs/adr/0010-efflorescence-mir2-cache-function-restore.md
112
+ - docs/adr/0011-efflorescence-unboxed-globals.md
113
+ - docs/adr/0012-efflorescence-startup-snapshot.md
114
+ - docs/adr/0013-efflorescence-frame-acquisition.md
99
115
  - docs/efflorescence-call-arities.md
100
116
  - docs/efflorescence-call-investigation.md
101
117
  - docs/efflorescence-call-transfer.md
@@ -110,10 +126,15 @@ files:
110
126
  - docs/efflorescence-m4.md
111
127
  - docs/efflorescence-m5.md
112
128
  - docs/efflorescence-m6.md
129
+ - docs/efflorescence-mir2-cache.md
113
130
  - docs/efflorescence-operand-decoding.md
114
131
  - docs/efflorescence-phase2-ja.md
115
132
  - docs/efflorescence-phase2.md
116
133
  - docs/efflorescence-register-initialization.md
134
+ - docs/efflorescence-ruby-wasm-phase1.md
135
+ - docs/efflorescence-spinel-linear-memory.md
136
+ - docs/efflorescence-startup-snapshot.md
137
+ - docs/efflorescence-unboxed-globals.md
117
138
  - docs/efflorescence.md
118
139
  - docs/spinel-string-aset-inplace-proposal.md
119
140
  - examples/.gitignore
@@ -154,8 +175,10 @@ files:
154
175
  - lib/wardite/efflorescence/i64_arithmetic.rb
155
176
  - lib/wardite/efflorescence/inspection.rb
156
177
  - lib/wardite/efflorescence/ir.rb
178
+ - lib/wardite/efflorescence/mir_cache.rb
157
179
  - lib/wardite/efflorescence/optimizer.rb
158
180
  - lib/wardite/efflorescence/register_validation.rb
181
+ - lib/wardite/efflorescence/snapshot.rb
159
182
  - lib/wardite/efflorescence/store_access.rb
160
183
  - lib/wardite/efflorescence/translator.rb
161
184
  - lib/wardite/efflorescence/vm.rb
@@ -172,6 +195,7 @@ files:
172
195
  - lib/wardite/wasi/consts.rb
173
196
  - lib/wardite/wasi/dirent_cache.rb
174
197
  - lib/wardite/wasi/preopens.rb
198
+ - lib/wardite/wasi/spinel.rb
175
199
  - lib/wardite/wasm_module.rb
176
200
  - misc/bench-value.rb
177
201
  - misc/slides/fib.c
@@ -183,10 +207,12 @@ files:
183
207
  - misc/slides/tokyo12.md
184
208
  - rbs_collection.lock.yaml
185
209
  - rbs_collection.yaml
210
+ - scripts/build_spinel_zig.rb
186
211
  - scripts/gen_alu.rb
187
212
  - scripts/gen_conv.rb
188
213
  - scripts/templates/alu_module.rb.tmpl
189
214
  - scripts/templates/conv_module.rb.tmpl
215
+ - scripts/verify_ruby_wasm.rb
190
216
  - sig/bundler.rbs
191
217
  - sig/fcntl.rbs
192
218
  - sig/generated/wardite.rbs
@@ -201,8 +227,10 @@ files:
201
227
  - sig/generated/wardite/efflorescence/i64_arithmetic.rbs
202
228
  - sig/generated/wardite/efflorescence/inspection.rbs
203
229
  - sig/generated/wardite/efflorescence/ir.rbs
230
+ - sig/generated/wardite/efflorescence/mir_cache.rbs
204
231
  - sig/generated/wardite/efflorescence/optimizer.rbs
205
232
  - sig/generated/wardite/efflorescence/register_validation.rbs
233
+ - sig/generated/wardite/efflorescence/snapshot.rbs
206
234
  - sig/generated/wardite/efflorescence/store_access.rbs
207
235
  - sig/generated/wardite/efflorescence/translator.rbs
208
236
  - sig/generated/wardite/efflorescence/vm.rbs
@@ -219,7 +247,10 @@ files:
219
247
  - sig/generated/wardite/wasi/consts.rbs
220
248
  - sig/generated/wardite/wasi/dirent_cache.rbs
221
249
  - sig/generated/wardite/wasi/preopens.rbs
250
+ - sig/generated/wardite/wasi/spinel.rbs
222
251
  - sig/generated/wardite/wasm_module.rbs
252
+ - sig/io_buffer.rbs
253
+ - sig/mir_cache_stdlib.rbs
223
254
  - sig/vernier.rbs
224
255
  - sig/wardite.rbs
225
256
  - spinel/README.md