BEAM-native JS engine and compiler#5
Open
dannote wants to merge 2614 commits into
Open
Conversation
0eb3475 to
7c1c574
Compare
75fdba5 to
527d5b9
Compare
# Conflicts: # lib/quickbeam/context.ex # lib/quickbeam/js/bundler.ex # lib/quickbeam/runtime.ex # mix.exs # mix.lock # npm.lock # package.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a BEAM-native JavaScript execution engine from the ground up. Before this PR, QuickBEAM executed JavaScript through the native QuickJS runtime only; there was no BEAM bytecode decoder, interpreter, or compiler backend.
This PR adds the full BEAM execution path: an Elixir QuickJS bytecode decoder, an interpreter that runs decoded QuickJS bytecode directly on the BEAM, and a compiler that lowers QuickJS bytecode into BEAM modules. The rest of the branch builds the runtime semantics, object model, compiler ABI, opcode metadata, audits, and parity fixes needed to make that new engine usable and maintainable.
Public API and runtime modes
mode: :beamsupport for running JavaScript through the BEAM VM backendmode: :autocompiler-backed execution with fallbackmode: :beam_compilerQUICKBEAM_MODE=beam_compilersupport for audit runs:beambackend viaQuickBEAM.disasm/2Error.captureStackTraceBytecode VM
Compiler backend
Compiler/interpreter architecture hardening
ObjectModel.InternalMethodsObjectModel.Getinto focused helpers for own lookup, ordinary get, prototype traversal, callback factories, symbol/length behavior, and exotic getsProxyDispatchOwnProperty,Prototype,Define,Delete, andHasPropertyAPIsRuntimeABIas the generated-code boundary and added disassembly coverage to prevent generated BEAM from calling lower-level VM internals directlyOpcodeSpec, including format/operand metadata, stack effects, lowering family/module/handler metadata, control-flow metadata, call arity, slot metadata, and branch metadataJavaScript semantics covered
Object,Array,Function,String,Number,BooleanMath,JSON,Date,RegExpMap,Set,WeakMap,WeakSet, collection iterators, and self-iterabilitySymbol, well-known symbols, property keys, andSymbol.toStringTagPromise,async/await, generators, delegatedyield*, and async generatorsProxyandReflect, including descriptor/prototype/extensibility invariantsTypedArray,ArrayBuffer,BigIntsuper, private fields, private methods, private accessors, static private members, brand checks, and constructor return semanticsObject.create,Object.assign,Object.fromEntries, freeze/seal/preventExtensions/isExtensible/isFrozen/isSealedeval,with, refs, globals, callback/global write freshness, delete semantics,in,instanceof,new, update operators, arithmetic/coercion edge cases, and BigInt operationsgosub/retfinally control flow, nested catches inside finally, break/continue through finally, and catch-region slot preservationwith/destructuringSemantic parity fixes discovered while bringing the backend online
[[Set]]failure handlingletloop closure snapshots for captured loop variablesclearIntervalcancellation during timer drain:__internal_proto__Static analysis and cleanup
ex_dna,ex_slop, andcredomix lintnow runs ExDNA with a zero-clone budget--no-starttest runs:modeAudit and benchmark tooling
bench/vm_compiler_compat.exsbench/vm_compiler_corpus.exsbench/vm_compiler_opcode_coverage.exsbench/vm_compiler_perf.exsbench/vm_compiler_semantic_gaps.exsbench/vm_compiler_test262.exstest/support/vm_compiler_audit.exCurrent compiler audit status
invalid, intentionally unsupported45.239µsto42.845µs1.113xRecent validation
mix reach.checkmix test test/vm/architecture_boundary_test.exs test/vm/opcode_spec_test.exs test/vm/compiler/lowering_registry_test.exs test/vm/compiler/abi_boundary_test.exs test/vm/compiler test/vm/runtime --max-failures 5mix test test/vm/modes/dual_mode_test.exs test/vm/modes/beam_compat_test.exs test/vm/semantics test/web_apis/beam_web_apis_test.exs test/vm/compiler test/vm/runtime --max-failures 5mix test --max-failures 5Previous broad validation:
mix compile --warnings-as-errorsmix lintmix dialyzermix test test/js/parser test/vm/auto_mode_test.exs test/vm/compiler_differential_test.exs test/web_apis/beam_fetch_test.exs test/web_apis/beam_text_encoding_test.exs test/web_apis/beam_buffer_test.exs test/web_apis/beam_streams_test.exs test/web_apis/event_source_test.exsmix test --no-start --exclude napi_addon --exclude napi_sqlite test/web_apis/event_source_test.exs test/web_apis/beam_event_source_test.exsPARSER_BENCH=vm_compiler_semantics ./autoresearch.shTEST262_LIMIT=1500 TEST262_CASE_TIMEOUT=5000 PARSER_BENCH=vm_compiler_test262 ./autoresearch.shQUICKBEAM_BUILD=1 MIX_ENV=test mix testMIX_ENV=test QUICKBEAM_BUILD=1 mix test test/vm/js_engine_test.exs --include js_engine --seed 0mix format --check-formattedmix credo --strictmix dialyzermix ex_dnazlint lib/quickbeam/*.zig lib/quickbeam/napi/*.zigbunx oxlint -c oxlint.json --type-aware --type-check priv/ts/bunx jscpd lib/quickbeam/*.zig priv/ts/*.ts --min-tokens 50 --threshold 0