wardite 1.2.1 → 1.3.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/README.md +17 -16
- data/Rakefile +0 -177
- data/benchmark/README.md +11 -37
- data/benchmark/call_cost_worker.rb +3 -2
- data/benchmark/compare.rb +1 -2
- data/benchmark/compare_linear_memory_loads.py +144 -0
- data/benchmark/i32_memory.wat +5 -1
- data/benchmark/investigate_calls.rb +3 -3
- data/benchmark/linear_memory_loads.wat +52 -0
- data/benchmark/optimization_worker.rb +3 -2
- data/benchmark/patches/adr0017-spinel-signed64.patch +190 -0
- data/benchmark/patches/adr0017-wardite-split-load64.patch +70 -0
- data/benchmark/results/adr0019-startup.json +1687 -0
- data/benchmark/results/adr0020-i64.json +2034 -0
- data/benchmark/results/adr0021-optimizer.json +5798 -0
- data/benchmark/results/adr0022-lazy-mir.json +3057 -0
- data/benchmark/results/crc8-stream-repeat.csv +89 -0
- data/benchmark/results/crc8-stream.csv +89 -0
- data/benchmark/results/linear-memory-loads-a2aa05227.csv +793 -0
- data/benchmark/results/linear-memory-loads-stage-b.csv +353 -0
- data/benchmark/results/linear-memory-loads.csv +1057 -0
- data/benchmark/results/real-workloads-baseline-2026-11-18.json +1741 -0
- data/benchmark/results/stack-vm-removal.json +334 -0
- data/benchmark/validate_m4.rb +0 -2
- data/docs/adr/0017-efflorescence-linear-memory-loads.md +90 -0
- data/docs/adr/0018-efflorescence-real-workload-measurement.md +126 -0
- data/docs/adr/0019-efflorescence-startup-quick-wins.md +85 -0
- data/docs/adr/0020-efflorescence-inline-i64-bit-operations.md +89 -0
- data/docs/adr/0021-efflorescence-optimize-real-functions.md +133 -0
- data/docs/adr/0022-efflorescence-lazy-function-build.md +111 -0
- data/docs/adr/0023-efflorescence-byte-sequences-and-copy-coalescing.md +56 -0
- data/docs/efflorescence-ja.md +6 -9
- data/docs/efflorescence-linear-memory-loads.md +134 -0
- data/docs/efflorescence-m6.md +1 -1
- data/docs/efflorescence-mir2-cache.md +7 -0
- data/docs/efflorescence-real-workloads.md +312 -0
- data/docs/efflorescence-spinel-linear-memory.md +2 -2
- data/docs/efflorescence.md +7 -8
- data/docs/stack-vm-removal.md +49 -0
- data/lib/wardite/cli/cli.rb +24 -21
- data/lib/wardite/efflorescence/byte_sequences.rb +80 -0
- data/lib/wardite/efflorescence/function_preparer.rb +64 -0
- data/lib/wardite/efflorescence/i64_arithmetic.rb +31 -0
- data/lib/wardite/efflorescence/inspection.rb +44 -12
- data/lib/wardite/efflorescence/ir.rb +33 -10
- data/lib/wardite/efflorescence/mir_cache.rb +10 -1
- data/lib/wardite/efflorescence/optimizer.rb +151 -42
- data/lib/wardite/efflorescence/store_access.rb +17 -0
- data/lib/wardite/efflorescence/translation_source.rb +50 -0
- data/lib/wardite/efflorescence/translator.rb +43 -13
- data/lib/wardite/efflorescence/vm.rb +116 -48
- data/lib/wardite/efflorescence.rb +3 -0
- data/lib/wardite/load.rb +47 -63
- data/lib/wardite/version.rb +1 -1
- data/lib/wardite.rb +21 -757
- data/scripts/build_spinel_zig.rb +1 -1
- data/sig/generated/wardite/cli/cli.rbs +4 -2
- data/sig/generated/wardite/efflorescence/byte_sequences.rbs +33 -0
- data/sig/generated/wardite/efflorescence/function_preparer.rbs +25 -0
- data/sig/generated/wardite/efflorescence/i64_arithmetic.rbs +19 -0
- data/sig/generated/wardite/efflorescence/inspection.rbs +8 -0
- data/sig/generated/wardite/efflorescence/ir.rbs +18 -2
- data/sig/generated/wardite/efflorescence/optimizer.rbs +41 -3
- data/sig/generated/wardite/efflorescence/store_access.rbs +5 -0
- data/sig/generated/wardite/efflorescence/translation_source.rbs +34 -0
- data/sig/generated/wardite/efflorescence/translator.rbs +11 -1
- data/sig/generated/wardite/efflorescence/vm.rbs +19 -9
- data/sig/generated/wardite/load.rbs +18 -18
- data/sig/generated/wardite.rbs +4 -155
- metadata +32 -17
- data/benchmark/compare_engines.rb +0 -119
- data/benchmark/engine_phases.rb +0 -30
- data/lib/wardite/alu_f32.generated.rb +0 -261
- data/lib/wardite/alu_f64.generated.rb +0 -261
- data/lib/wardite/alu_i32.generated.rb +0 -510
- data/lib/wardite/alu_i64.generated.rb +0 -572
- data/lib/wardite/convert.generated.rb +0 -340
- data/scripts/gen_alu.rb +0 -864
- data/scripts/gen_conv.rb +0 -86
- data/scripts/templates/alu_module.rb.tmpl +0 -20
- data/scripts/templates/conv_module.rb.tmpl +0 -20
- data/sig/generated/wardite/alu_f32.generated.rbs +0 -12
- data/sig/generated/wardite/alu_f64.generated.rbs +0 -12
- data/sig/generated/wardite/alu_i32.generated.rbs +0 -12
- data/sig/generated/wardite/alu_i64.generated.rbs +0 -12
- data/sig/generated/wardite/convert.generated.rbs +0 -12
data/lib/wardite/load.rb
CHANGED
|
@@ -140,15 +140,12 @@ module Wardite
|
|
|
140
140
|
class DecodedBody
|
|
141
141
|
attr_reader :instructions #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
142
142
|
attr_reader :blocks #: Array[Block]
|
|
143
|
-
attr_reader :has_eh_instructions #: bool
|
|
144
143
|
|
|
145
144
|
# @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
146
145
|
# @rbs blocks: Array[Block]
|
|
147
|
-
|
|
148
|
-
def initialize(instructions, blocks, has_eh_instructions)
|
|
146
|
+
def initialize(instructions, blocks)
|
|
149
147
|
@instructions = instructions
|
|
150
148
|
@blocks = blocks
|
|
151
|
-
@has_eh_instructions = has_eh_instructions
|
|
152
149
|
end
|
|
153
150
|
end
|
|
154
151
|
|
|
@@ -174,7 +171,7 @@ module Wardite
|
|
|
174
171
|
|
|
175
172
|
# @rbs return: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
176
173
|
def body
|
|
177
|
-
check_features(@type_section
|
|
174
|
+
check_features(@type_section) if @instruction_bytes
|
|
178
175
|
# The caller can mutate both the array and the Block objects in it.
|
|
179
176
|
@decoded = nil
|
|
180
177
|
@body
|
|
@@ -202,20 +199,16 @@ module Wardite
|
|
|
202
199
|
end
|
|
203
200
|
|
|
204
201
|
# @rbs types: TypeSection?
|
|
205
|
-
# @rbs stack: bool
|
|
206
202
|
# @rbs return: void
|
|
207
|
-
def check_features(types
|
|
208
|
-
if stack && locals_type.include?(:exnref)
|
|
209
|
-
raise LoadError, "stack engine does not support exnref"
|
|
210
|
-
end
|
|
203
|
+
def check_features(types)
|
|
211
204
|
if (bytes = @instruction_bytes)
|
|
212
205
|
decoded = BinaryLoader.decode_body(StringIO.new(bytes))
|
|
213
|
-
check_decoded(decoded, types
|
|
206
|
+
check_decoded(decoded, types)
|
|
214
207
|
install_decoded(decoded)
|
|
215
208
|
elsif (decoded = @decoded)
|
|
216
|
-
check_decoded(decoded, types
|
|
209
|
+
check_decoded(decoded, types)
|
|
217
210
|
else
|
|
218
|
-
check_instructions(@body, types
|
|
211
|
+
check_instructions(@body, types)
|
|
219
212
|
end
|
|
220
213
|
end
|
|
221
214
|
|
|
@@ -231,35 +224,26 @@ module Wardite
|
|
|
231
224
|
|
|
232
225
|
# @rbs decoded: DecodedBody
|
|
233
226
|
# @rbs types: TypeSection?
|
|
234
|
-
# @rbs stack: bool
|
|
235
227
|
# @rbs return: void
|
|
236
|
-
def check_decoded(decoded, types
|
|
237
|
-
|
|
238
|
-
raise LoadError, "stack engine does not support EH"
|
|
239
|
-
end
|
|
240
|
-
decoded.blocks.each { |block| check_block(block, types, stack) }
|
|
228
|
+
def check_decoded(decoded, types)
|
|
229
|
+
decoded.blocks.each { |block| check_block(block, types) }
|
|
241
230
|
end
|
|
242
231
|
|
|
243
232
|
# @rbs instructions: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
244
233
|
# @rbs types: TypeSection?
|
|
245
|
-
# @rbs stack: bool
|
|
246
234
|
# @rbs return: void
|
|
247
|
-
def check_instructions(instructions, types
|
|
235
|
+
def check_instructions(instructions, types)
|
|
248
236
|
instructions.each do |instruction|
|
|
249
|
-
if stack && BinaryLoader.eh_instruction?(instruction[1])
|
|
250
|
-
raise LoadError, "stack engine does not support EH"
|
|
251
|
-
end
|
|
252
237
|
instruction[2].each do |operand|
|
|
253
|
-
check_block(operand, types
|
|
238
|
+
check_block(operand, types) if operand.is_a?(Block)
|
|
254
239
|
end
|
|
255
240
|
end
|
|
256
241
|
end
|
|
257
242
|
|
|
258
243
|
# @rbs block: Block
|
|
259
244
|
# @rbs types: TypeSection?
|
|
260
|
-
# @rbs stack: bool
|
|
261
245
|
# @rbs return: void
|
|
262
|
-
def check_block(block, types
|
|
246
|
+
def check_block(block, types)
|
|
263
247
|
index = block.type_index
|
|
264
248
|
if index >= 0
|
|
265
249
|
params = types&.defined_types&.[](index)
|
|
@@ -267,12 +251,12 @@ module Wardite
|
|
|
267
251
|
raise LoadError, "invalid block type index #{index}" unless params && results
|
|
268
252
|
block.resolve(params, results)
|
|
269
253
|
end
|
|
270
|
-
if stack && (index >= 0 || block.result_types.include?(:exnref))
|
|
271
|
-
raise LoadError, "stack engine does not support indexed/reference block signatures"
|
|
272
|
-
end
|
|
273
254
|
end
|
|
274
255
|
end
|
|
275
256
|
|
|
257
|
+
# Keep the code section for on-demand MIR inspection after the host has
|
|
258
|
+
# accessed the mutable decoded bodies or edited the store.
|
|
259
|
+
attr_accessor :source_bytes #: String?
|
|
276
260
|
attr_accessor :func_codes #:Array[CodeBody]
|
|
277
261
|
|
|
278
262
|
# @rbs return: void
|
|
@@ -280,6 +264,7 @@ module Wardite
|
|
|
280
264
|
self.name = "Code"
|
|
281
265
|
self.code = 0xa
|
|
282
266
|
|
|
267
|
+
@source_bytes = nil
|
|
283
268
|
@func_codes = []
|
|
284
269
|
end
|
|
285
270
|
end
|
|
@@ -395,28 +380,26 @@ module Wardite
|
|
|
395
380
|
# @rbs mir_cache_verify: Symbol
|
|
396
381
|
# @rbs mir_cache_eager: bool
|
|
397
382
|
# @rbs return: Instance
|
|
398
|
-
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true, engine: :
|
|
383
|
+
def self.load_from_buffer(buf, import_object: {}, enable_wasi: true, engine: :efflorescence, disabled_optimizations: [], mir_profile: false, mir_cache: nil, mir_cache_verify: :checksum, mir_cache_eager: false)
|
|
399
384
|
start = Time.now.to_f #: Float
|
|
400
385
|
unless mir_cache_verify == :checksum || mir_cache_verify == :sha256
|
|
401
386
|
raise ArgumentError, "MIR cache verification must be checksum or sha256"
|
|
402
387
|
end
|
|
388
|
+
raise LoadError, "unknown engine: #{engine}" unless engine == :efflorescence
|
|
403
389
|
@buf = buf
|
|
404
390
|
cache = nil #: Efflorescence::MIRCache?
|
|
405
|
-
if mir_cache
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
cache = Efflorescence::MIRCache.new(mir_cache, bytes, configuration, verify: mir_cache_verify, eager: mir_cache_eager)
|
|
414
|
-
@buf = StringIO.new(bytes)
|
|
415
|
-
end
|
|
391
|
+
if mir_cache && !mir_profile
|
|
392
|
+
require "wardite/efflorescence/mir_cache" unless RUBY_ENGINE == "spinel"
|
|
393
|
+
# Hash the same bytes that the decoder will see, even if the file changes.
|
|
394
|
+
bytes = buf.read || "".b
|
|
395
|
+
configuration = Efflorescence::Configuration.new(disabled_optimizations)
|
|
396
|
+
disabled_optimizations = configuration.disabled
|
|
397
|
+
cache = Efflorescence::MIRCache.new(mir_cache, bytes, configuration, verify: mir_cache_verify, eager: mir_cache_eager)
|
|
398
|
+
@buf = StringIO.new(bytes)
|
|
416
399
|
end
|
|
417
400
|
|
|
418
401
|
version = preamble
|
|
419
|
-
sections_ = sections(!cache.nil
|
|
402
|
+
sections_ = sections(!cache.nil?, true)
|
|
420
403
|
@buf = buf if cache
|
|
421
404
|
|
|
422
405
|
wasi_env = nil
|
|
@@ -425,18 +408,15 @@ module Wardite
|
|
|
425
408
|
wasi_env = if RUBY_ENGINE == "spinel"
|
|
426
409
|
require "wardite/wasi"
|
|
427
410
|
Wardite::WasiSnapshotPreview1.new
|
|
428
|
-
|
|
411
|
+
else
|
|
429
412
|
require "wardite/efflorescence/wasi"
|
|
430
413
|
Wardite::Efflorescence::WasiSnapshotPreview1.new
|
|
431
|
-
else
|
|
432
|
-
require "wardite/wasi"
|
|
433
|
-
Wardite::WasiSnapshotPreview1.new
|
|
434
414
|
end
|
|
435
415
|
import_object[:wasi_snapshot_preview1] = wasi_env
|
|
436
416
|
end
|
|
437
417
|
|
|
438
418
|
return Instance.new(import_object, engine: engine, disabled_optimizations: disabled_optimizations,
|
|
439
|
-
mir_profile: mir_profile, mir_cache: cache) do |i|
|
|
419
|
+
mir_profile: mir_profile, mir_cache: cache, eager_mir: mir_cache_eager) do |i|
|
|
440
420
|
i.version = version
|
|
441
421
|
i.sections = sections_
|
|
442
422
|
i.wasi = wasi_env
|
|
@@ -467,8 +447,9 @@ module Wardite
|
|
|
467
447
|
end
|
|
468
448
|
|
|
469
449
|
# @rbs defer_code: bool
|
|
450
|
+
# @rbs keep_code: bool
|
|
470
451
|
# @rbs return: Array[Section]
|
|
471
|
-
def self.sections(defer_code = false)
|
|
452
|
+
def self.sections(defer_code = false, keep_code = false)
|
|
472
453
|
sections = [] #: Array[Section]
|
|
473
454
|
|
|
474
455
|
loop do
|
|
@@ -497,7 +478,7 @@ module Wardite
|
|
|
497
478
|
when Wardite::SectionElement
|
|
498
479
|
elem_section
|
|
499
480
|
when Wardite::SectionCode
|
|
500
|
-
code_section(defer_code)
|
|
481
|
+
code_section(defer_code, keep_code)
|
|
501
482
|
when Wardite::SectionData
|
|
502
483
|
data_section
|
|
503
484
|
when Wardite::Const::SectionDataCount
|
|
@@ -765,12 +746,23 @@ module Wardite
|
|
|
765
746
|
end
|
|
766
747
|
|
|
767
748
|
# @rbs defer_code: bool
|
|
749
|
+
# @rbs keep_code: bool
|
|
768
750
|
# @rbs return: CodeSection
|
|
769
|
-
def self.code_section(defer_code = false)
|
|
770
|
-
dest = CodeSection.new
|
|
751
|
+
def self.code_section(defer_code = false, keep_code = false)
|
|
771
752
|
size = fetch_uleb128(@buf)
|
|
772
|
-
|
|
773
|
-
|
|
753
|
+
bytes = assert_read(@buf, size)
|
|
754
|
+
section = decode_code_section(bytes, defer_code)
|
|
755
|
+
section.source_bytes = bytes.freeze if keep_code
|
|
756
|
+
section
|
|
757
|
+
end
|
|
758
|
+
|
|
759
|
+
# @rbs bytes: String
|
|
760
|
+
# @rbs defer_code: bool
|
|
761
|
+
# @rbs return: CodeSection
|
|
762
|
+
def self.decode_code_section(bytes, defer_code = false)
|
|
763
|
+
dest = CodeSection.new
|
|
764
|
+
dest.size = bytes.bytesize
|
|
765
|
+
sbuf = StringIO.new(bytes)
|
|
774
766
|
|
|
775
767
|
len = fetch_uleb128(sbuf)
|
|
776
768
|
len.times { dest.func_codes << read_function_body(sbuf, defer_code) }
|
|
@@ -817,14 +809,12 @@ module Wardite
|
|
|
817
809
|
def self.decode_body(buf)
|
|
818
810
|
dest = [] #: Array[[Symbol, Symbol, Array[operandItem], Integer?, Integer?]]
|
|
819
811
|
blocks = [] #: Array[Block]
|
|
820
|
-
has_eh_instructions = false
|
|
821
812
|
# HINT: [symname, index of op, index of else, index of end]
|
|
822
813
|
branching_stack = [] #: Array[[Symbol, Integer, Integer, Integer]]
|
|
823
814
|
fixed_stack = [] #: Array[[Symbol, Integer, Integer, Integer]]
|
|
824
815
|
while opcode = buf.getbyte
|
|
825
816
|
spec = resolve_spec(opcode, buf)
|
|
826
817
|
code = spec.code
|
|
827
|
-
has_eh_instructions ||= eh_instruction?(code)
|
|
828
818
|
operand = [] #: Array[operandItem]
|
|
829
819
|
spec.operand_types.each do |typ|
|
|
830
820
|
case typ
|
|
@@ -909,7 +899,7 @@ module Wardite
|
|
|
909
899
|
raise "[BUG] unknown sym #{sym.inspect}"
|
|
910
900
|
end
|
|
911
901
|
end
|
|
912
|
-
DecodedBody.new(dest, blocks
|
|
902
|
+
DecodedBody.new(dest, blocks)
|
|
913
903
|
rescue => e
|
|
914
904
|
require "pp"
|
|
915
905
|
$stderr.puts "parsed:::"
|
|
@@ -918,12 +908,6 @@ module Wardite
|
|
|
918
908
|
raise e
|
|
919
909
|
end
|
|
920
910
|
|
|
921
|
-
# @rbs code: Symbol
|
|
922
|
-
# @rbs return: bool
|
|
923
|
-
def self.eh_instruction?(code)
|
|
924
|
-
code == :try_table || code == :throw || code == :throw_ref
|
|
925
|
-
end
|
|
926
|
-
|
|
927
911
|
# Decode s33, distinguishing the one-byte value/void forms from indices.
|
|
928
912
|
# @rbs buf: File|StringIO
|
|
929
913
|
# @rbs return: Block
|
data/lib/wardite/version.rb
CHANGED