wardite 0.9.0 → 1.1.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.
- checksums.yaml +4 -4
- data/LICENSE +191 -0
- data/Makefile +14 -0
- data/README.md +107 -2
- data/Rakefile +5 -0
- data/Steepfile +1 -0
- data/assets/wardite.svg +12 -0
- data/benchmark/README.md +500 -0
- data/benchmark/build_call_profile.rb +42 -0
- data/benchmark/call_cost_worker.rb +27 -0
- data/benchmark/compare.rb +93 -0
- data/benchmark/compare_call_types.rb +212 -0
- data/benchmark/compare_dispatch.rb +123 -0
- data/benchmark/compare_engines.rb +119 -0
- data/benchmark/compare_optimizations.rb +139 -0
- data/benchmark/engine_phases.rb +30 -0
- data/benchmark/figures/README.md +35 -0
- data/benchmark/figures/plot_spinel_comparison.py +137 -0
- data/benchmark/figures/spinel_new_vm_candlestick.png +0 -0
- data/benchmark/figures/spinel_new_vm_candlestick.svg +7615 -0
- data/benchmark/figures/spinel_new_vm_summary.csv +9 -0
- data/benchmark/figures/spinel_new_vm_summary.json +82 -0
- data/benchmark/float_m5.wat +42 -0
- data/benchmark/i32_call_arities.wat +89 -0
- data/benchmark/i32_calls.wat +174 -0
- data/benchmark/i32_memory.wat +58 -0
- data/benchmark/i32_mix.wat +80 -0
- data/benchmark/i64_m4.wat +55 -0
- data/benchmark/investigate_calls.rb +231 -0
- data/benchmark/investigate_generated_guards.rb +218 -0
- data/benchmark/m3_call_worker.rb +38 -0
- data/benchmark/measure_m1.rb +51 -0
- data/benchmark/measure_m2.rb +55 -0
- data/benchmark/measure_m3_calls.rb +89 -0
- data/benchmark/measure_m4.rb +134 -0
- data/benchmark/measure_m5_boundary.rb +41 -0
- data/benchmark/measure_mir_cache_verify.rb +58 -0
- data/benchmark/measure_ruby_wasm_cache_hit.rb +59 -0
- data/benchmark/measure_ruby_wasm_startup.rb +43 -0
- data/benchmark/measure_wasi_write.rb +75 -0
- data/benchmark/optimization_worker.rb +23 -0
- data/benchmark/results/call_arities_exploratory_2026-11-04.json +4320 -0
- data/benchmark/results/call_arities_spinel_2026-11-04.json +1200 -0
- data/benchmark/results/call_cost_spinel_2026-11-04.json +2392 -0
- data/benchmark/results/call_protocol_exploratory_2026-11-04.json +3947 -0
- data/benchmark/results/call_protocol_profile_2026-11-04.json +383 -0
- data/benchmark/results/call_protocol_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/call_protocol_spinel_2026-11-04.json +913 -0
- data/benchmark/results/call_types_ruby_2026-11-04.json +1212 -0
- data/benchmark/results/call_types_spinel_2026-11-04.json +923 -0
- data/benchmark/results/efflorescence-m1-cruby.json +799 -0
- data/benchmark/results/efflorescence-m1-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-bulk-loop.json +820 -0
- data/benchmark/results/efflorescence-m2-i32-cruby.json +799 -0
- data/benchmark/results/efflorescence-m2-i32-spinel.json +799 -0
- data/benchmark/results/efflorescence-m2-memory.json +408 -0
- data/benchmark/results/efflorescence-mir2-cache-integrity.json +390 -0
- data/benchmark/results/efflorescence-unboxed-globals.json +3451 -0
- data/benchmark/results/generated_guards_exploratory_2026-11-04.json +1225 -0
- data/benchmark/results/generated_guards_profile_2026-11-04.json +592 -0
- data/benchmark/results/generated_guards_spinel_2026-11-04.json +1650 -0
- data/benchmark/results/generated_guards_validation_2026-11-04.json +256 -0
- data/benchmark/results/inlining_engines_2026-11-04.json +241 -0
- data/benchmark/results/inlining_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/inlining_spinel_2026-11-04.json +893 -0
- data/benchmark/results/operand_decode_exploratory_2026-11-04.json +1319 -0
- data/benchmark/results/operand_decode_ruby_2026-11-04.json +1213 -0
- data/benchmark/results/operand_decode_spinel_2026-11-04.json +924 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04.json +454 -0
- data/benchmark/results/selective_reset_spinel_2026-11-04_exploratory.json +2679 -0
- data/benchmark/results/spinel_fetch_root_patch_2026-11-04.json +4523 -0
- data/benchmark/results/while_final_compiler_comparison_2026-11-04.json +324 -0
- data/benchmark/results/while_patched_external_2026-11-04.json +220 -0
- data/benchmark/results/while_user_unpatched_2026-11-04.json +230 -0
- data/benchmark/summarize_call_profile.py +54 -0
- data/benchmark/validate_m1_eh.rb +34 -0
- data/benchmark/validate_m2.rb +119 -0
- data/benchmark/validate_m3.rb +44 -0
- data/benchmark/validate_m4.rb +95 -0
- data/benchmark/validate_m5.rb +108 -0
- data/docs/adr/0001-efflorescence-m1-control-and-eh.md +319 -0
- data/docs/adr/0002-efflorescence-m2-memory-and-globals.md +185 -0
- data/docs/adr/0003-efflorescence-m3-host-and-indirect-calls.md +228 -0
- data/docs/adr/0004-efflorescence-m4-i64.md +202 -0
- data/docs/adr/0005-efflorescence-m5-floating-point.md +127 -0
- data/docs/adr/0006-efflorescence-m6-coverage-parity.md +101 -0
- data/docs/adr/0007-efflorescence-ruby-wasm-phase1.md +75 -0
- data/docs/adr/0008-efflorescence-ruby-wasm-phase2.md +75 -0
- data/docs/adr/0009-efflorescence-mir2-cache-integrity-modes.md +77 -0
- data/docs/adr/0010-efflorescence-mir2-cache-function-restore.md +80 -0
- data/docs/adr/0011-efflorescence-unboxed-globals.md +89 -0
- data/docs/adr/0012-efflorescence-startup-snapshot.md +173 -0
- data/docs/adr/0013-efflorescence-frame-acquisition.md +114 -0
- data/docs/efflorescence-call-arities.md +115 -0
- data/docs/efflorescence-call-investigation.md +155 -0
- data/docs/efflorescence-call-transfer.md +128 -0
- data/docs/efflorescence-call-types.md +102 -0
- data/docs/efflorescence-coverage-ja.md +351 -0
- data/docs/efflorescence-generated-c-guards.md +410 -0
- data/docs/efflorescence-inlining.md +165 -0
- data/docs/efflorescence-ja.md +155 -0
- data/docs/efflorescence-m1.md +160 -0
- data/docs/efflorescence-m2.md +233 -0
- data/docs/efflorescence-m3.md +131 -0
- data/docs/efflorescence-m4.md +88 -0
- data/docs/efflorescence-m5.md +82 -0
- data/docs/efflorescence-m6.md +95 -0
- data/docs/efflorescence-mir2-cache.md +123 -0
- data/docs/efflorescence-operand-decoding.md +105 -0
- data/docs/efflorescence-phase2-ja.md +225 -0
- data/docs/efflorescence-phase2.md +240 -0
- data/docs/efflorescence-register-initialization.md +75 -0
- data/docs/efflorescence-ruby-wasm-phase1.md +90 -0
- data/docs/efflorescence-spinel-linear-memory.md +72 -0
- data/docs/efflorescence-startup-snapshot.md +60 -0
- data/docs/efflorescence-unboxed-globals.md +61 -0
- data/docs/efflorescence.md +144 -0
- data/docs/spinel-string-aset-inplace-proposal.md +200 -0
- data/lib/wardite/alu_f32.generated.rb +11 -2
- data/lib/wardite/alu_f64.generated.rb +11 -2
- data/lib/wardite/alu_i32.generated.rb +54 -17
- data/lib/wardite/alu_i64.generated.rb +73 -31
- data/lib/wardite/cli/cli.rb +112 -29
- data/lib/wardite/const.rb +1 -0
- data/lib/wardite/efflorescence/float_arithmetic.rb +216 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +257 -0
- data/lib/wardite/efflorescence/inspection.rb +165 -0
- data/lib/wardite/efflorescence/ir.rb +1164 -0
- data/lib/wardite/efflorescence/mir_cache.rb +657 -0
- data/lib/wardite/efflorescence/optimizer.rb +580 -0
- data/lib/wardite/efflorescence/register_validation.rb +362 -0
- data/lib/wardite/efflorescence/snapshot.rb +229 -0
- data/lib/wardite/efflorescence/store_access.rb +366 -0
- data/lib/wardite/efflorescence/translator.rb +866 -0
- data/lib/wardite/efflorescence/vm.rb +1170 -0
- data/lib/wardite/efflorescence/wasi.rb +52 -0
- data/lib/wardite/efflorescence.rb +17 -0
- data/lib/wardite/errors.rb +20 -0
- data/lib/wardite/float_bits.rb +46 -0
- data/lib/wardite/instruction.rb +35 -4
- data/lib/wardite/leb128.rb +33 -12
- data/lib/wardite/load.rb +292 -143
- data/lib/wardite/value.rb +169 -175
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite/wasi/consts.rb +1 -0
- data/lib/wardite/wasi/spinel.rb +41 -0
- data/lib/wardite/wasi.rb +483 -268
- data/lib/wardite/wasm_module.rb +6 -3
- data/lib/wardite.rb +360 -98
- data/rbs_collection.lock.yaml +36 -96
- data/scripts/gen_alu.rb +121 -21
- data/scripts/verify_ruby_wasm.rb +70 -0
- data/sig/generated/wardite/cli/cli.rbs +23 -6
- data/sig/generated/wardite/const.rbs +2 -0
- data/sig/generated/wardite/efflorescence/float_arithmetic.rbs +65 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +99 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +64 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +888 -0
- data/sig/generated/wardite/efflorescence/mir_cache.rbs +236 -0
- data/sig/generated/wardite/efflorescence/optimizer.rbs +189 -0
- data/sig/generated/wardite/efflorescence/register_validation.rbs +104 -0
- data/sig/generated/wardite/efflorescence/snapshot.rbs +83 -0
- data/sig/generated/wardite/efflorescence/store_access.rbs +145 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +218 -0
- data/sig/generated/wardite/efflorescence/vm.rbs +240 -0
- data/sig/generated/wardite/efflorescence/wasi.rbs +34 -0
- data/sig/generated/wardite/errors.rbs +12 -0
- data/sig/generated/wardite/float_bits.rbs +30 -0
- data/sig/generated/wardite/instruction.rbs +22 -1
- data/sig/generated/wardite/leb128.rbs +3 -1
- data/sig/generated/wardite/load.rbs +59 -7
- data/sig/generated/wardite/value.rbs +70 -11
- data/sig/generated/wardite/wasi/consts.rbs +2 -0
- data/sig/generated/wardite/wasi/spinel.rbs +15 -0
- data/sig/generated/wardite/wasi.rbs +111 -4
- data/sig/generated/wardite.rbs +114 -13
- data/sig/mir_cache_stdlib.rbs +5 -0
- data/sig/vernier.rbs +2 -2
- data/spinel/README.md +30 -0
- data/spinel/bin/wardite.rb +6 -0
- data/spinel/patches/0001-io-buffer-string-view.patch +699 -0
- data/spinel/patches/0002-io-buffer-allocation-error.patch +47 -0
- data/spinel/spin.toml +7 -0
- metadata +154 -3
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
# Generated from lib/wardite/efflorescence/mir_cache.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Wardite
|
|
4
|
+
module Efflorescence
|
|
5
|
+
# Local, opt-in cache of the verified output of Lowerer. Bump CODE_VERSION
|
|
6
|
+
# when the generated code or its interpretation changes, including opcodes,
|
|
7
|
+
# optimizer/validator fixes, and changes to the metadata used by the VM.
|
|
8
|
+
class MIRCache
|
|
9
|
+
MAGIC: untyped
|
|
10
|
+
|
|
11
|
+
FORMAT_VERSION: ::Integer
|
|
12
|
+
|
|
13
|
+
CODE_VERSION: ::Integer
|
|
14
|
+
|
|
15
|
+
DIGEST_SIZE: ::Integer
|
|
16
|
+
|
|
17
|
+
LENGTH_SIZE: ::Integer
|
|
18
|
+
|
|
19
|
+
INTEGRITY_SIZE: untyped
|
|
20
|
+
|
|
21
|
+
SAMPLE_EDGE: untyped
|
|
22
|
+
|
|
23
|
+
SAMPLE_STEP: untyped
|
|
24
|
+
|
|
25
|
+
SAMPLE_BLOCK: untyped
|
|
26
|
+
|
|
27
|
+
MAX_BYTES: untyped
|
|
28
|
+
|
|
29
|
+
TYPES: untyped
|
|
30
|
+
|
|
31
|
+
TYPE_IDS: untyped
|
|
32
|
+
|
|
33
|
+
USES_I64: ::Integer
|
|
34
|
+
|
|
35
|
+
USES_FLOAT: ::Integer
|
|
36
|
+
|
|
37
|
+
USES_EH: ::Integer
|
|
38
|
+
|
|
39
|
+
USES_STORE: ::Integer
|
|
40
|
+
|
|
41
|
+
USES_DYNAMIC_CALLS: ::Integer
|
|
42
|
+
|
|
43
|
+
FUNCTION_FLAGS: untyped
|
|
44
|
+
|
|
45
|
+
class Invalid < StandardError
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Identifies the module, the generated code, and the host build.
|
|
49
|
+
attr_reader key: String
|
|
50
|
+
|
|
51
|
+
# All records are little-endian. Vectors carry a nonnegative 32-bit element count.
|
|
52
|
+
# A record count is bounded by the bytes still available to decode it.
|
|
53
|
+
class Reader
|
|
54
|
+
# @rbs bytes: String
|
|
55
|
+
def initialize: (String bytes) -> untyped
|
|
56
|
+
|
|
57
|
+
# @rbs length: Integer
|
|
58
|
+
# @rbs return: String
|
|
59
|
+
def bytes: (Integer length) -> String
|
|
60
|
+
|
|
61
|
+
# @rbs return: Integer
|
|
62
|
+
def integer: () -> Integer
|
|
63
|
+
|
|
64
|
+
# @rbs width: Integer
|
|
65
|
+
# @rbs return: Integer
|
|
66
|
+
def count: (Integer width) -> Integer
|
|
67
|
+
|
|
68
|
+
# @rbs format: String
|
|
69
|
+
# @rbs width: Integer
|
|
70
|
+
# @rbs return: Array[Integer]
|
|
71
|
+
def vector: (String format, Integer width) -> Array[Integer]
|
|
72
|
+
|
|
73
|
+
# @rbs return: Array[Symbol]
|
|
74
|
+
def types: () -> Array[Symbol]
|
|
75
|
+
|
|
76
|
+
# @rbs return: void
|
|
77
|
+
def finish: () -> void
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
# @rbs length: Integer
|
|
82
|
+
# @rbs return: void
|
|
83
|
+
def ensure_bytes: (Integer length) -> void
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class Writer
|
|
87
|
+
attr_reader bytes: String
|
|
88
|
+
|
|
89
|
+
def initialize: () -> untyped
|
|
90
|
+
|
|
91
|
+
# @rbs *values: Integer
|
|
92
|
+
# @rbs return: void
|
|
93
|
+
def integers: (*Integer values) -> void
|
|
94
|
+
|
|
95
|
+
# @rbs values: Array[Integer]
|
|
96
|
+
# @rbs format: String
|
|
97
|
+
# @rbs return: void
|
|
98
|
+
def vector: (Array[Integer] values, ?String format) -> void
|
|
99
|
+
|
|
100
|
+
# @rbs types: Array[Symbol]
|
|
101
|
+
# @rbs return: void
|
|
102
|
+
def types: (Array[Symbol] types) -> void
|
|
103
|
+
|
|
104
|
+
# @rbs function: Function
|
|
105
|
+
# @rbs return: void
|
|
106
|
+
def function: (Function function) -> void
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class Decoder
|
|
110
|
+
include Opcode
|
|
111
|
+
|
|
112
|
+
# Reuse the semantic register roles for fixed operands. Lowering
|
|
113
|
+
# moves direct call arguments into a side table and leaves optional
|
|
114
|
+
# destinations and return operands to be checked against signatures.
|
|
115
|
+
REGISTER_MASKS: Array[Integer]
|
|
116
|
+
|
|
117
|
+
EXTRA_OPERANDS: Array[Symbol?]
|
|
118
|
+
|
|
119
|
+
# @rbs reader: Reader
|
|
120
|
+
# @rbs instance: Wardite::Instance
|
|
121
|
+
# @rbs entries: Array[FunctionEntry]
|
|
122
|
+
def initialize: (Reader reader, Wardite::Instance instance, Array[FunctionEntry] entries) -> untyped
|
|
123
|
+
|
|
124
|
+
# @rbs return: Array[Function]
|
|
125
|
+
def decode: () -> Array[Function]
|
|
126
|
+
|
|
127
|
+
private
|
|
128
|
+
|
|
129
|
+
# @rbs body: Wardite::CodeSection::CodeBody
|
|
130
|
+
# @rbs entry: FunctionEntry
|
|
131
|
+
# @rbs index: Integer
|
|
132
|
+
# @rbs return: Function
|
|
133
|
+
def read_function: (Wardite::CodeSection::CodeBody body, FunctionEntry entry, Integer index) -> Function
|
|
134
|
+
|
|
135
|
+
# @rbs function: Function
|
|
136
|
+
# @rbs return: Array[[Integer, Array[Integer]]]
|
|
137
|
+
def read_sites: (Function function) -> Array[[ Integer, Array[Integer] ]]
|
|
138
|
+
|
|
139
|
+
# @rbs function: Function
|
|
140
|
+
# @rbs return: DynamicCallSite
|
|
141
|
+
def read_dynamic_site: (Function function) -> DynamicCallSite
|
|
142
|
+
|
|
143
|
+
# @rbs function: Function
|
|
144
|
+
# @rbs return: MemorySite
|
|
145
|
+
def read_memory_site: (Function function) -> MemorySite
|
|
146
|
+
|
|
147
|
+
# @rbs function: Function
|
|
148
|
+
# @rbs handler_count: Integer
|
|
149
|
+
# @rbs return: CatchTarget
|
|
150
|
+
def read_catch: (Function function, Integer handler_count) -> CatchTarget
|
|
151
|
+
|
|
152
|
+
# @rbs function: Function
|
|
153
|
+
# @rbs return: void
|
|
154
|
+
def check_code: (Function function) -> void
|
|
155
|
+
|
|
156
|
+
# @rbs tag: Integer
|
|
157
|
+
# @rbs return: Array[Symbol]
|
|
158
|
+
def tag_types: (Integer tag) -> Array[Symbol]
|
|
159
|
+
|
|
160
|
+
# @rbs function: Function
|
|
161
|
+
# @rbs registers: Array[Integer]
|
|
162
|
+
# @rbs types: Array[Symbol]
|
|
163
|
+
# @rbs return: void
|
|
164
|
+
def check_arguments: (Function function, Array[Integer] registers, Array[Symbol] types) -> void
|
|
165
|
+
|
|
166
|
+
# @rbs function: Function
|
|
167
|
+
# @rbs slot: Integer
|
|
168
|
+
# @rbs types: Array[Symbol]
|
|
169
|
+
# @rbs return: void
|
|
170
|
+
def check_result: (Function function, Integer slot, Array[Symbol] types) -> void
|
|
171
|
+
|
|
172
|
+
# @rbs target: Integer
|
|
173
|
+
# @rbs limit: Integer
|
|
174
|
+
# @rbs return: void
|
|
175
|
+
def check_target: (Integer target, Integer limit) -> void
|
|
176
|
+
|
|
177
|
+
# @rbs [T] (Array[T] values, Integer index) -> T
|
|
178
|
+
def at: [T] (Array[T] values, Integer index) -> T
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# @rbs directory: String
|
|
182
|
+
# @rbs wasm: String
|
|
183
|
+
# @rbs configuration: Configuration
|
|
184
|
+
# @rbs verify: Symbol
|
|
185
|
+
def initialize: (String directory, String wasm, Configuration configuration, ?verify: Symbol) -> untyped
|
|
186
|
+
|
|
187
|
+
# Restore against module declarations so a miss can decode and check the
|
|
188
|
+
# Wasm bodies before Store initialization or any host lookup.
|
|
189
|
+
# @rbs instance: Wardite::Instance
|
|
190
|
+
# @rbs return: Array[Function]?
|
|
191
|
+
def read: (Wardite::Instance instance) -> Array[Function]?
|
|
192
|
+
|
|
193
|
+
# @rbs instance: Wardite::Instance
|
|
194
|
+
# @rbs ir: IR
|
|
195
|
+
# @rbs return: void
|
|
196
|
+
def write: (Wardite::Instance instance, IR ir) -> void
|
|
197
|
+
|
|
198
|
+
private
|
|
199
|
+
|
|
200
|
+
# @rbs instance: Wardite::Instance
|
|
201
|
+
# @rbs return: Array[FunctionEntry]
|
|
202
|
+
def module_entries: (Wardite::Instance instance) -> Array[FunctionEntry]
|
|
203
|
+
|
|
204
|
+
# @rbs return: String
|
|
205
|
+
def read_verified_payload: () -> String
|
|
206
|
+
|
|
207
|
+
# @rbs payload: String
|
|
208
|
+
# @rbs length: String
|
|
209
|
+
# @rbs return: String
|
|
210
|
+
def self.sample_checksum: (String payload, String length) -> String
|
|
211
|
+
|
|
212
|
+
# Opening without blocking keeps a FIFO from stalling the start of a run.
|
|
213
|
+
# @rbs path: String
|
|
214
|
+
# @rbs header: String
|
|
215
|
+
# @rbs prefix_size: Integer
|
|
216
|
+
# @rbs return: String
|
|
217
|
+
def self.read_contents: (String path, String header, Integer prefix_size) -> String
|
|
218
|
+
|
|
219
|
+
# Exclusive creation protects a concurrent writer's temporary file.
|
|
220
|
+
# Close the file before publishing it under the cache key.
|
|
221
|
+
# @rbs directory: String
|
|
222
|
+
# @rbs destination: String
|
|
223
|
+
# @rbs prefix: String
|
|
224
|
+
# @rbs payload: String
|
|
225
|
+
# @rbs return: void
|
|
226
|
+
def self.publish: (String directory, String destination, String prefix, String payload) -> void
|
|
227
|
+
|
|
228
|
+
# Include the module's import identities, and every function's signature
|
|
229
|
+
# and index mapping. The live entries and hosts are always linked afresh.
|
|
230
|
+
# @rbs instance: Wardite::Instance
|
|
231
|
+
# @rbs entries: Array[FunctionEntry]
|
|
232
|
+
# @rbs return: String
|
|
233
|
+
def encode_layout: (Wardite::Instance instance, Array[FunctionEntry] entries) -> String
|
|
234
|
+
end
|
|
235
|
+
end
|
|
236
|
+
end
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
# Generated from lib/wardite/efflorescence/optimizer.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Wardite
|
|
4
|
+
module Efflorescence
|
|
5
|
+
class Configuration
|
|
6
|
+
FEATURES: untyped
|
|
7
|
+
|
|
8
|
+
attr_reader disabled: Array[Symbol]
|
|
9
|
+
|
|
10
|
+
# @rbs disabled: Array[Symbol]
|
|
11
|
+
def initialize: (Array[Symbol] disabled) -> untyped
|
|
12
|
+
|
|
13
|
+
# @rbs feature: Symbol
|
|
14
|
+
# @rbs return: bool
|
|
15
|
+
def enabled?: (Symbol feature) -> bool
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# All transformations use instruction ordinals. Only the final lowering
|
|
19
|
+
# changes PCs to integer-array offsets. Every rewrite repairs branch edges.
|
|
20
|
+
class Rewrite
|
|
21
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
22
|
+
def initialize: (Wardite::Efflorescence::Function function) -> untyped
|
|
23
|
+
|
|
24
|
+
# @rbs pc: Integer
|
|
25
|
+
# @rbs return: void
|
|
26
|
+
def mark: (Integer pc) -> void
|
|
27
|
+
|
|
28
|
+
# @rbs instruction: Wardite::Efflorescence::Instruction
|
|
29
|
+
# @rbs return: void
|
|
30
|
+
def emit: (Wardite::Efflorescence::Instruction instruction) -> void
|
|
31
|
+
|
|
32
|
+
# @rbs return: void
|
|
33
|
+
def finish: () -> void
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# A shared CFG includes exceptional edges with their edge-local writes.
|
|
37
|
+
# Handler shapes are checked independently of definite assignment.
|
|
38
|
+
class FlowGraph
|
|
39
|
+
attr_reader normal: Array[Array[Integer]]
|
|
40
|
+
|
|
41
|
+
attr_reader exceptional: Array[Array[Wardite::Efflorescence::CatchTarget]]
|
|
42
|
+
|
|
43
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
44
|
+
def initialize: (Wardite::Efflorescence::Function function) -> untyped
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
# @rbs pc: Integer
|
|
49
|
+
# @rbs stack: Array[Integer]
|
|
50
|
+
# @rbs return: void
|
|
51
|
+
def merge: (Integer pc, Array[Integer] stack) -> void
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class Analysis
|
|
55
|
+
# @rbs @flow: Wardite::Efflorescence::FlowGraph?
|
|
56
|
+
attr_reader leaders: Array[Integer]
|
|
57
|
+
|
|
58
|
+
attr_reader reads: Array[Integer]
|
|
59
|
+
|
|
60
|
+
attr_reader writes: Array[Integer]
|
|
61
|
+
|
|
62
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
63
|
+
def initialize: (Wardite::Efflorescence::Function function) -> untyped
|
|
64
|
+
|
|
65
|
+
# Ordinary optimization passes need only the summary above. Build the full
|
|
66
|
+
# normal CFG once for validation; EH summaries also need it for leaders.
|
|
67
|
+
# @rbs return: Wardite::Efflorescence::FlowGraph
|
|
68
|
+
def flow: () -> Wardite::Efflorescence::FlowGraph
|
|
69
|
+
|
|
70
|
+
# @rbs register: Integer
|
|
71
|
+
# @rbs return: bool
|
|
72
|
+
def single_use?: (Integer register) -> bool
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
module Passes
|
|
76
|
+
# Expand only small, straight-line leaves from a snapshot of the IR.
|
|
77
|
+
# One round avoids transitive/exponential expansion and keeps recursion
|
|
78
|
+
# on the ordinary CALL path. Existing local passes clean up the copies.
|
|
79
|
+
class Inlining
|
|
80
|
+
MAX_INSTRUCTIONS: ::Integer
|
|
81
|
+
|
|
82
|
+
MAX_REGISTERS: ::Integer
|
|
83
|
+
|
|
84
|
+
MAX_ADDED_INSTRUCTIONS: ::Integer
|
|
85
|
+
|
|
86
|
+
MAX_ADDED_REGISTERS: ::Integer
|
|
87
|
+
|
|
88
|
+
# @rbs ir: Wardite::Efflorescence::IR
|
|
89
|
+
# @rbs return: Array[Integer]
|
|
90
|
+
def run: (Wardite::Efflorescence::IR ir) -> Array[Integer]
|
|
91
|
+
|
|
92
|
+
private
|
|
93
|
+
|
|
94
|
+
# Explicit whitelist: new opcodes must opt into inlining. In particular,
|
|
95
|
+
# traps, profiling records, control flow and nested calls stay intact.
|
|
96
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
97
|
+
# @rbs return: bool
|
|
98
|
+
def eligible?: (Wardite::Efflorescence::Function function) -> bool
|
|
99
|
+
|
|
100
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
101
|
+
# @rbs callees: Wardite::Efflorescence::IR
|
|
102
|
+
# @rbs return: bool
|
|
103
|
+
def expand_calls: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::IR callees) -> bool
|
|
104
|
+
|
|
105
|
+
# @rbs caller: Wardite::Efflorescence::Function
|
|
106
|
+
# @rbs callee: Wardite::Efflorescence::Function
|
|
107
|
+
# @rbs call: Wardite::Efflorescence::Instruction
|
|
108
|
+
# @rbs rewrite: Wardite::Efflorescence::Rewrite
|
|
109
|
+
# @rbs return: void
|
|
110
|
+
def expand: (Wardite::Efflorescence::Function caller, Wardite::Efflorescence::Function callee, Wardite::Efflorescence::Instruction call, Wardite::Efflorescence::Rewrite rewrite) -> void
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
class CopyPropagation
|
|
114
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
115
|
+
# @rbs return: void
|
|
116
|
+
def run: (Wardite::Efflorescence::Function function) -> void
|
|
117
|
+
|
|
118
|
+
private
|
|
119
|
+
|
|
120
|
+
# Redirect an adjacent producer into the COPY destination. The producer
|
|
121
|
+
# temporary has one definition and one use in the entire function, and
|
|
122
|
+
# nobody can enter at the COPY. No value is moved across another op.
|
|
123
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
124
|
+
# @rbs return: void
|
|
125
|
+
def coalesce_results: (Wardite::Efflorescence::Function function) -> void
|
|
126
|
+
|
|
127
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
128
|
+
# @rbs return: void
|
|
129
|
+
def propagate: (Wardite::Efflorescence::Function function) -> void
|
|
130
|
+
|
|
131
|
+
# Backward liveness inside each basic block removes copies overwritten
|
|
132
|
+
# before any read (e.g. an inlined parameter initializer). All registers
|
|
133
|
+
# are conservatively live across edges; no value moves across a branch.
|
|
134
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
135
|
+
# @rbs return: void
|
|
136
|
+
def remove_overwritten_copies: (Wardite::Efflorescence::Function function) -> void
|
|
137
|
+
|
|
138
|
+
# Keep snapshot and join copies unless their destination has no reads
|
|
139
|
+
# anywhere. Iteration also removes copies feeding another dead copy.
|
|
140
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
141
|
+
# @rbs return: void
|
|
142
|
+
def remove_dead_copies: (Wardite::Efflorescence::Function function) -> void
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
class ImmediateSpecialization
|
|
146
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
147
|
+
# @rbs return: void
|
|
148
|
+
def run: (Wardite::Efflorescence::Function function) -> void
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class BranchFusion
|
|
152
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
153
|
+
# @rbs return: void
|
|
154
|
+
def run: (Wardite::Efflorescence::Function function) -> void
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
class Superinstructions
|
|
158
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
159
|
+
# @rbs return: void
|
|
160
|
+
def run: (Wardite::Efflorescence::Function function) -> void
|
|
161
|
+
end
|
|
162
|
+
end
|
|
163
|
+
|
|
164
|
+
class Optimizer
|
|
165
|
+
# @rbs configuration: Wardite::Efflorescence::Configuration
|
|
166
|
+
def initialize: (Wardite::Efflorescence::Configuration configuration) -> untyped
|
|
167
|
+
|
|
168
|
+
# Never mutate the translator's semantic MIR; retain it for inspection
|
|
169
|
+
# and differential execution. Each pass can also be run independently.
|
|
170
|
+
# @rbs ir: Wardite::Efflorescence::IR
|
|
171
|
+
# @rbs return: Wardite::Efflorescence::IR
|
|
172
|
+
def optimize: (Wardite::Efflorescence::IR ir) -> Wardite::Efflorescence::IR
|
|
173
|
+
|
|
174
|
+
private
|
|
175
|
+
|
|
176
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
177
|
+
# @rbs return: void
|
|
178
|
+
def optimize_function: (Wardite::Efflorescence::Function function) -> void
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
class Lowerer
|
|
182
|
+
WIDTH: ::Integer
|
|
183
|
+
|
|
184
|
+
# @rbs ir: Wardite::Efflorescence::IR
|
|
185
|
+
# @rbs return: void
|
|
186
|
+
def compile: (Wardite::Efflorescence::IR ir) -> void
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# Generated from lib/wardite/efflorescence/register_validation.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Wardite
|
|
4
|
+
module Efflorescence
|
|
5
|
+
# Verify definite assignment once, after optimization and before execution.
|
|
6
|
+
# This makes stale temporary slots harmless when a frame is reused. Keep
|
|
7
|
+
# states per basic block, rather than per instruction, to bound their size.
|
|
8
|
+
class RegisterValidation
|
|
9
|
+
# Keep each word within Spinel's fixed-width Integer.
|
|
10
|
+
WORD_SHIFT: ::Integer
|
|
11
|
+
|
|
12
|
+
WORD_BITS: untyped
|
|
13
|
+
|
|
14
|
+
WORD_MASK: untyped
|
|
15
|
+
|
|
16
|
+
class Block
|
|
17
|
+
attr_reader first: Integer
|
|
18
|
+
|
|
19
|
+
attr_reader limit: Integer
|
|
20
|
+
|
|
21
|
+
attr_reader defined: Array[Integer]
|
|
22
|
+
|
|
23
|
+
attr_reader successors: Array[Integer]
|
|
24
|
+
|
|
25
|
+
attr_accessor pending: bool
|
|
26
|
+
|
|
27
|
+
# @rbs first: Integer
|
|
28
|
+
# @rbs limit: Integer
|
|
29
|
+
def initialize: (Integer first, Integer limit) -> untyped
|
|
30
|
+
|
|
31
|
+
# Incoming facts only lose definitions after the first reachable edge.
|
|
32
|
+
# Return true when a changed block needs to enter the worklist.
|
|
33
|
+
# @rbs incoming: Array[Integer]
|
|
34
|
+
# @rbs return: bool
|
|
35
|
+
def merge: (Array[Integer] incoming) -> bool
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
39
|
+
# @rbs return: void
|
|
40
|
+
# @rbs ir: Wardite::Efflorescence::IR?
|
|
41
|
+
# @rbs tags: Array[Wardite::Efflorescence::Tag]?
|
|
42
|
+
def validate: (Wardite::Efflorescence::Function function, ?Wardite::Efflorescence::IR? ir, ?tags: Array[Wardite::Efflorescence::Tag]?) -> void
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
# Visit predecessors before joins where possible, then revisit changed
|
|
47
|
+
# states across backedges until the worklist is empty.
|
|
48
|
+
# @rbs blocks: Array[Wardite::Efflorescence::RegisterValidation::Block]
|
|
49
|
+
# @rbs block_for_pc: Array[Integer]
|
|
50
|
+
# @rbs flow: Wardite::Efflorescence::FlowGraph
|
|
51
|
+
# @rbs return: Array[Integer]
|
|
52
|
+
def reverse_postorder: (Array[Wardite::Efflorescence::RegisterValidation::Block] blocks, Array[Integer] block_for_pc, Wardite::Efflorescence::FlowGraph flow) -> Array[Integer]
|
|
53
|
+
|
|
54
|
+
# @rbs words: Array[Integer]
|
|
55
|
+
# @rbs register: Integer
|
|
56
|
+
# @rbs return: void
|
|
57
|
+
def mark: (Array[Integer] words, Integer register) -> void
|
|
58
|
+
|
|
59
|
+
# @rbs words: Array[Integer]
|
|
60
|
+
# @rbs register: Integer
|
|
61
|
+
# @rbs return: bool
|
|
62
|
+
def marked?: (Array[Integer] words, Integer register) -> bool
|
|
63
|
+
|
|
64
|
+
# Validate all registers, including unreachable instructions and table-only
|
|
65
|
+
# operands. Numeric registers are checked before flat execution.
|
|
66
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
67
|
+
# @rbs return: void
|
|
68
|
+
# @rbs ir: Wardite::Efflorescence::IR?
|
|
69
|
+
# @rbs tags: Array[Wardite::Efflorescence::Tag]?
|
|
70
|
+
def validate_types: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::IR? ir, Array[Wardite::Efflorescence::Tag]? tags) -> void
|
|
71
|
+
|
|
72
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
73
|
+
# @rbs instruction: Wardite::Efflorescence::Instruction
|
|
74
|
+
# @rbs reads: Array[Integer]
|
|
75
|
+
# @rbs destination: Integer
|
|
76
|
+
# @rbs return: void
|
|
77
|
+
def validate_extended_instruction: (Wardite::Efflorescence::Function function, Wardite::Efflorescence::Instruction instruction, Array[Integer] reads, Integer destination) -> void
|
|
78
|
+
|
|
79
|
+
# @rbs tags: Array[Wardite::Efflorescence::Tag]?
|
|
80
|
+
# @rbs index: Integer
|
|
81
|
+
# @rbs size: Integer
|
|
82
|
+
# @rbs return: Array[Symbol]
|
|
83
|
+
def payload_types: (Array[Wardite::Efflorescence::Tag]? tags, Integer index, Integer size) -> Array[Symbol]
|
|
84
|
+
|
|
85
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
86
|
+
# @rbs register: Integer
|
|
87
|
+
# @rbs types: Array[Symbol]
|
|
88
|
+
# @rbs return: void
|
|
89
|
+
def check_result: (Wardite::Efflorescence::Function function, Integer register, Array[Symbol] types) -> void
|
|
90
|
+
|
|
91
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
92
|
+
# @rbs register: Integer
|
|
93
|
+
# @rbs type: Symbol
|
|
94
|
+
# @rbs return: void
|
|
95
|
+
def check_register: (Wardite::Efflorescence::Function function, Integer register, Symbol type) -> void
|
|
96
|
+
|
|
97
|
+
# @rbs function: Wardite::Efflorescence::Function
|
|
98
|
+
# @rbs register: Integer
|
|
99
|
+
# @rbs type: Symbol
|
|
100
|
+
# @rbs return: void
|
|
101
|
+
def check_destination: (Wardite::Efflorescence::Function function, Integer register, Symbol type) -> void
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# Generated from lib/wardite/efflorescence/snapshot.rb with RBS::Inline
|
|
2
|
+
|
|
3
|
+
module Wardite
|
|
4
|
+
module Efflorescence
|
|
5
|
+
class SavedFrame
|
|
6
|
+
attr_reader pool_index: Integer
|
|
7
|
+
|
|
8
|
+
attr_reader pc: Integer
|
|
9
|
+
|
|
10
|
+
attr_reader return_register: Integer
|
|
11
|
+
|
|
12
|
+
attr_reader registers: Array[Integer]
|
|
13
|
+
|
|
14
|
+
attr_reader handlers: Array[Integer]
|
|
15
|
+
|
|
16
|
+
# @rbs pool_index: Integer
|
|
17
|
+
# @rbs pc: Integer
|
|
18
|
+
# @rbs return_register: Integer
|
|
19
|
+
# @rbs registers: Array[Integer]
|
|
20
|
+
# @rbs handlers: Array[Integer]
|
|
21
|
+
def initialize: (Integer pool_index, Integer pc, Integer return_register, Array[Integer] registers, Array[Integer] handlers) -> untyped
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Startup snapshot of a WASI command (ADR 0012). The state is saved just
|
|
25
|
+
# before the first WASI call whose result is not fixed by the key, and a
|
|
26
|
+
# later run with the same key resumes from there.
|
|
27
|
+
class Snapshot
|
|
28
|
+
MAGIC: untyped
|
|
29
|
+
|
|
30
|
+
FORMAT_VERSION: ::Integer
|
|
31
|
+
|
|
32
|
+
PAGE_SIZE: ::Integer
|
|
33
|
+
|
|
34
|
+
ZERO_PAGE: untyped
|
|
35
|
+
|
|
36
|
+
# Their results depend only on values in the key, or are frozen into the
|
|
37
|
+
# snapshot (clocks and random bytes). fd_filestat_get is allowed for
|
|
38
|
+
# stdio only: CRuby probes fds 0-2 before anything else.
|
|
39
|
+
ALLOWED: untyped
|
|
40
|
+
|
|
41
|
+
attr_reader path: String
|
|
42
|
+
|
|
43
|
+
# @rbs directory: String
|
|
44
|
+
# @rbs instance: Wardite::Instance
|
|
45
|
+
# @rbs mir_cache: Wardite::Efflorescence::MIRCache
|
|
46
|
+
def initialize: (String directory, Wardite::Instance instance, Wardite::Efflorescence::MIRCache mir_cache) -> untyped
|
|
47
|
+
|
|
48
|
+
# Does this host call end the deterministic prefix of the run?
|
|
49
|
+
# @rbs host: Wardite::Efflorescence::HostFunction
|
|
50
|
+
# @rbs registers: Array[Integer]
|
|
51
|
+
# @rbs sources: Array[Integer]
|
|
52
|
+
# @rbs return: bool
|
|
53
|
+
def checkpoint?: (Wardite::Efflorescence::HostFunction host, Array[Integer] registers, Array[Integer] sources) -> bool
|
|
54
|
+
|
|
55
|
+
# Saving is best effort: any refusal or I/O error leaves the run as is.
|
|
56
|
+
# @rbs instance: Wardite::Instance
|
|
57
|
+
# @rbs frames: Array[Wardite::Efflorescence::Frame]
|
|
58
|
+
# @rbs return: void
|
|
59
|
+
def save: (Wardite::Instance instance, Array[Wardite::Efflorescence::Frame] frames) -> void
|
|
60
|
+
|
|
61
|
+
# Validate everything before touching the Store, so a rejected file
|
|
62
|
+
# leaves a fresh instance for the normal start.
|
|
63
|
+
# @rbs vm: Wardite::Efflorescence::VM
|
|
64
|
+
# @rbs return: Array[Wardite::Efflorescence::SavedFrame]?
|
|
65
|
+
def restore: (Wardite::Efflorescence::VM vm) -> Array[Wardite::Efflorescence::SavedFrame]?
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# The top frame resumes at its host call. Callers resume after the call
|
|
70
|
+
# that created the frame above them, which writes its return register.
|
|
71
|
+
# @rbs functions: Array[Wardite::Efflorescence::Function]
|
|
72
|
+
# @rbs frames: Array[Wardite::Efflorescence::SavedFrame]
|
|
73
|
+
# @rbs index: Integer
|
|
74
|
+
# @rbs return: void
|
|
75
|
+
def check_frame: (Array[Wardite::Efflorescence::Function] functions, Array[Wardite::Efflorescence::SavedFrame] frames, Integer index) -> void
|
|
76
|
+
|
|
77
|
+
# @rbs message: String
|
|
78
|
+
# @rbs started: Float
|
|
79
|
+
# @rbs return: void
|
|
80
|
+
def trace: (String message, ?Float started) -> void
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|