Where things are

View Source

This page tells you where each part of erlang_wasm lives: every directory, every module with what it does, and for each area of the runtime the module where a call enters, what configures it, where you extend it, the suites that test it and the page to read. Use it when you are about to change the runtime and need to find the code, or when you have a behaviour and want its tests.

A module is supported when you may call it and rely on it; a change that breaks it is in the changelog. An extension point is a behaviour: callbacks your own module exports so the runtime can call them. Everything else is internal and may change in any release. Start here has the full statement, including the few internal functions a guide documents.

wasm_architecture_SUITE checks that every module appears on this page.

The source tree

directorywhat it holds
src/the core runtime: front end, instances, interpreter, memory, compiled tier, supervision
src/component/the Component Model: decoding, linking, the Canonical ABI
src/wasi/WASI preview 1, WASI 0.2, WASI 0.3, sockets and HTTP
src/worker/the workers, the language adapters and request cleanup
include/shared records and constants
c_src/the optional file NIF, wasi_file_nif.c
priv/script_v1/the boot scripts the shipped JavaScript and Python adapters load
examples/plugin_worker, qjs_worker and nn_upper, three demonstrations to read and copy
test/every Common Test suite, one *_SUITE.erl each
test/support/what suites share: fake adapters, the conformance runners, wasm_asm
test/fixtures/the WebAssembly files suites load; Fixtures says where each comes from
test/audit/the measurement record: PERF.md, ATTEMPTS.md and the reviews
bench/the benchmark arms; bench/paths/README.md says what each measures
scripts/build and fetch scripts for the NIF and the fixtures, the dependency audit, and how CI splits the suites into shards
docs/the pages the documentation site is built from

The folders under src/ are for finding modules. They are not namespaces: every module is prefixed wasm_ or wasi_, and the build compiles them all into one application.

src/: the front end

modulewhat it doesstatus
wasm_decodeWebAssembly binary format decoderinternal
wasm_decode_codeinstruction and expression decodinginternal
wasm_decode_simdthe 0xFD opcode space: fixed-width SIMDinternal
wasm_decode_gcthe 0xFB opcode space: garbage collectioninternal
wasm_decode_atomicthe 0xFE opcode space: threadsinternal
wasm_leb128LEB128 varint decoding, strict per the binary formatinternal
wasm_encodeWebAssembly binary format encoder: a #module{} back to bytesinternal
wasm_encode_codeinstruction and expression encodinginternal
wasm_encode_simdthe 0xFD opcode space, written back to bytesinternal
wasm_encode_gcthe 0xFB opcode space, written back to bytesinternal
wasm_encode_atomicthe 0xFE opcode space, written back to bytesinternal
wasm_validatemodule-level validationinternal
wasm_validate_codefunction body validationinternal
wasm_validate_simdoperand types for the 0xFD vector opcode spaceinternal
wasm_validate_atomictypes and alignment for the 0xFE opcode spaceinternal
wasm_typestype identity: when two declared types are the same typeinternal
wasm_watthe text format, parsed into the same #module{} the decoder producesinternal
wasm_wat_lextokens of the text formatinternal
wasm_wat_sexptokens to a tree, and where your parenthesis is missinginternal
wasm_wat_numnumeric literals of the text formatinternal
wasm_wat_instrwhat immediate an instruction takes, by nameinternal
wasm_wastspecification scripts: the .wast format the conformance suite usesinternal

src/: the runtime

modulewhat it doesstatus
wasmthe front door: every public operation on a module or an instancesupported
wasm_limitsresource limits, and what they do not coversupported
wasm_enginenode-wide resource accounting, including the page budgetsupported
wasm_errorstructured errors and trapssupported
wasm_instanceinstantiation: a validated module made executableinternal
wasm_execthe interpreterinternal
wasm_memorylinear memory backed by chunked atomics arraysinternal; new/1 supported
wasm_tabletables, with reference semanticsinternal
wasm_globalmutable globals kept outside an instance's state: cells two instances share, and slots for integer globals nothing else seesinternal
wasm_heapthe garbage-collected object storeinternal
wasm_keeperthe authority on who still holds a shared resourceinternal
wasm_waitmemory.atomic.wait and memory.atomic.notifyinternal
wasm_lifetimemakes a spawned process die with the process responsible for itinternal
wasm_module_cachecompiled modules, cached node-wide and keyed by content hashinternal
wasm_file_cachea directory of files, bounded by total size, oldest firstinternal
wasm_snapshotinitialized runtime snapshots: an immutable copy of a started guestinternal
wasm_snapshot_ownerone process per snapshot, holding what a term cannot holdinternal
wasm_snapshot_filethe on-disk form of a snapshotinternal
wasm_snapshot_storea directory of snapshot images, keyed by what makes one validinternal; purge/0 supported

src/: numerics

modulewhat it doesstatus
wasm_numconversion between IEEE 754 bit patterns and the runtime float forminternal
wasm_num_floatfloating-point arithmetic over that representationinternal
wasm_num_truncfloat to integer truncation, both familiesinternal
wasm_simdfixed-width SIMD: v128 values and the operations on theminternal

src/: the compiled tier

modulewhat it doesstatus
wasm_jitwhen a module gets compiled, and how a call reaches the resultinternal; a few functions supported
wasm_corethe Core Erlang back end: generates and compiles the formsinternal
wasm_code_slotswho still uses a piece of generated code, and when its slot is reusedinternal
wasm_code_cachecompiled code kept on disk across node restartsinternal; purge/0 supported
wasm_unit_filethe on-disk form of compiled code built ahead of timeinternal
wasm_jit_supthe processes that compile modules, under supervisioninternal

src/: the application

modulewhat it doesstatus
wasm_appapplication callbackinternal
wasm_suproot supervisorinternal
wasm_subsupone subsystem, with a restart budget of its owninternal
wasm_storeowns every long-lived ETS table, and does nothing elseinternal

src/component/

modulewhat it doesstatus
wasm_componentdecode and run a component: the Component Model's entry pointsupported
wasm_component_linkreads a component's wiring and builds its coresinternal
wasm_component_typesdecodes a component's type section into value descriptorsinternal
wasm_canonthe Canonical ABI lift and lower for component valuesinternal
wasm_resourcesper-component-instance resource handle tablesinternal
wasm_asyncthe async Canonical ABI runtimeinternal; host_read/3, host_sink/2 supported
wasm_recipebuilds a component from a recipeinternal

src/wasi/

modulewhat it doesstatus
wasiruns a WASI command and gives back its exit status and outputsupported
wasi_preview1WASI preview 1, as an Erlang host interfacesupported
wasi_fsfile access for WASI, over whichever backend is availableinternal; backend/0 supported
wasi_pathcapability-scoped path resolutioninternal
wasi_file_nifoptional native file access that closes the WASI path raceinternal
wasi_netthe network capabilityinternal
wasi_socksockets, as WASI descriptorsinternal
wasi_preview2the WASI 0.2 host: the wasi:* interfaces a component importssupported
wasi_p2_filesystemthe wasi:filesystem part of the WASI 0.2 hostinternal
wasi_p2_socketsthe wasi:sockets part of the WASI 0.2 hostinternal
wasi_sock2the TCP backend for wasi:sockets, over OTP's socket moduleinternal
wasi_nnthe wasi:nn host, and the behaviour an inference backend implementssupported
wasi_preview3the WASI 0.3 hostsupported
wasi_p3_filesystemwasi:filesystem at 0.3, over the same preopened descriptorsinternal
wasi_p3_socketswasi:sockets at 0.3, the same sockets under the same grantinternal
wasi_p3_httpwasi:http at 0.3internal
wasi_httpthe outbound path of wasi:http@0.2 and its resourcessupported
wasi_http_listenera live HTTP server that serves a wasi:http componentsupported
wasi_http_transportthe pluggable transport behind wasi:httpextension point
wasi_http_h1the HTTP/1.1 transport, over the h1 clientsupported
wasi_http_h2the HTTP/2 transport, over the h2 clientsupported

src/worker/

modulewhat it doesstatus
wasm_instance_workera worker owning one WebAssembly instancesupported
wasm_actora component that handles typed messages one at a time, as a supervised processsupported
wasm_actor_registrywhere senders find an actor's queue; forgets an actor that diedinternal
wasm_script_workerthe worker kernel: processes, deadlines, bounded streams, an adaptersupported
wasm_worker_adapterthe behaviour that teaches the kernel one languageextension point
wasm_worker_errorthe worker's error type, and the closed set of its kindssupported
wasm_adapter_conformancethe case list an adapter must pass, run from Common Testsupported
wasm_javascriptJavaScript from an image of an already-started enginesupported
wasm_javascript_commandJavaScript that arrives at request timesupported
wasm_pythonPython from an image of an already-started interpretersupported
wasm_python_commandPython that arrives at request timesupported
wasm_luaLua from an image of an already-started interpretersupported
wasm_script_v1the script_v1 profile the shipped adapters speakinternal
wasm_worker_fsthe file operations a request makes, in the calling processinternal
wasm_worker_imagesthe images script workers share, node-wideinternal
wasm_worker_reaperwho cleans up after a request when its owner is goneinternal
wasm_worker_supsupervises the reaper, so a worker needs nobody to start oneinternal
wasm_cleanup_managerthe node-wide cleanup managerinternal
wasm_cleanup_stewardthe per-request cleanup stewardinternal
wasm_cleanup_steward_supthe dynamic supervisor for cleanup stewardsinternal

Find the area you are changing

Each row is one area of the runtime. Enter at is where a call comes in. Configured by names the options and application settings that change its behaviour. Extend through is where your own code plugs in, if anywhere. Every suite named is a file in test/.

areaenter atmodulesconfigured byextend throughtestsread
Binary encodewasm:encode/1, wasm:load({wat, Source})wasm_encode, wasm_encode_code, wasm_encode_simd, wasm_encode_gc, wasm_encode_atomic, wasm_leb128max_module_bytesnonewasm_encode_SUITE, wasm_prop_SUITE, wasm_core_prop_SUITEGetting started, then wasm_encode's module doc
Binary decodewasm:compile/2wasm_decode, wasm_decode_code, wasm_decode_simd, wasm_decode_gc, wasm_decode_atomic, wasm_leb128max_module_bytesnonewasm_spec_SUITE, wasm_decode_immediates_SUITE, wasm_decode_retain_SUITE, wasm_prop_SUITEAdding an instruction
Validation and type identitywasm:compile/2, wasm:validate/1wasm_validate, wasm_validate_code, wasm_validate_simd, wasm_validate_atomic, wasm_typesmax_rec_groupsnonewasm_spec_SUITE, wasm_validate_scalar_SUITE, wasm_annotate_SUITE, wasm_prop_SUITEAdding an instruction
Text format and wastwasm:compile({wat, Source}), wasm_wast:script/1wasm_wat, wasm_wat_lex, wasm_wat_sexp, wasm_wat_num, wasm_wat_instr, wasm_wastnonenonewasm_wat_SUITE, wasm_wat_lex_SUITE, wasm_wast_SUITEFeatures and conformance
Instantiate and linkwasm:instantiate/3, then wasm_instance:new/3wasm_instance, wasm_table, wasm_globalinstantiate options; table_grow_limithost functionswasm_linking_SUITE, wasm_funcref_SUITE, wasm_scale_SUITEHold modules and instances, Host functions
Interpreterwasm:call/3wasm_exec, wasm_num, wasm_num_float, wasm_num_trunc, wasm_simdnonenonewasm_spec_SUITE, wasm_num_SUITE, wasm_simd_SUITE, wasm_relaxed_simd_SUITE, wasm_tailcall_SUITE, wasm_exception_SUITE, wasm_native_SUITEThe path of a call
Limitsthe limits map of wasm:instantiate/3, or of one callwasm_limits, wasm_execthe limits map, or a wasm_limits presetnonewasm_budget_SUITE, wasm_trap_effects_SUITE, wasm_memory_limit_SUITEHold modules and instances
The error modelevery call that can failwasm_errornonenonewasm_trap_effects_SUITE, wasm_prop_SUITE, wasm_component_malformed_SUITEConcepts
Threads and atomicsa shared memory from wasm_memory:new/1; memory.atomic.waitwasm_wait, wasm_decode_atomic, wasm_validate_atomic, wasm_memorynonenonewasm_threads_SUITE, wasm_spec_SUITEFeatures and conformance
GC proposalthe struct, array and i31 instructionswasm_heap, wasm_decode_gcgc_alloc_threshold and the other settings in the GC pagenonewasm_gc_SUITE, wasm_gc_collect_SUITE, wasm_gc_lease_SUITE, wasm_gc_roots_SUITEGarbage collection
Memory and the page budgetwasm_memory:new/1, wasm_memory:grow/2wasm_memory, wasm_keeper, wasm_enginewasm_engine:set_page_limit/1nonewasm_resource_SUITE, wasm_shared_pages_SUITE, wasm_paged_memory_SUITE, wasm_prop_SUITE, wasm_memory64_SUITEMemory
Compiled tierwasm_jit:entry/3, wasm_jit:after_call/2, wasm:precompile/2, wasm:preload/1wasm_jit, wasm_core, wasm_code_slots, wasm_code_cache, wasm_unit_file, wasm_jit_supcompile, profile, code_cache_dir, your application's wasm_modulesnonewasm_core_SUITE, wasm_core_prop_SUITE, wasm_jit_lifetime_SUITE, wasm_jit_bounds_SUITE, wasm_code_slots_SUITE, wasm_paged_memory_SUITE, wasm_precompile_SUITE, wasm_spec_SUITE, wasm_exception_SUITE (compiled_frames), wasm_trap_effects_SUITE (both_tiers)The compiled tier, Compiled tier internals
Snapshotswasm:snapshot/2, wasm:restore/3wasm_snapshot, wasm_snapshot_owner, wasm_snapshot_file, wasm_snapshot_storemax_snapshot_bytes, snapshot_dir, max_snapshot_dir_bytessnapshot_hookswasm_snapshot_SUITE, wasm_component_snapshot_SUITESnapshots
Module and file cachewasm:load/1wasm_module_cache, wasm_file_cachemax_resident_modules, max_resident_module_bytes, max_module_loads_per_secondnonewasm_module_cache_SUITE, wasm_file_cache_SUITEHold modules and instances
Application and supervisionapplication:ensure_all_started(wasm)wasm_app, wasm_sup, wasm_subsup, wasm_store, wasm_lifetimenonenonewasm_lifetime_SUITE, wasm_worker_sup_SUITE, wasm_architecture_SUITEThe supervision tree
WASI preview 1wasi_preview1:imports/1, wasi:run/2wasi, wasi_preview1, wasi_fs, wasi_path, wasi_net, wasi_sock, wasi_file_nifthe WASI options; require_native_fsthe optional file NIFwasi_SUITE, wasi_net_SUITE, wasi_net_escape_SUITE, wasi_sock_SUITE, wasi_sock_ext_SUITE, wasi_random_SUITE, wasi_nif_SUITE, wasi_nul_path_SUITE, wasi_durability_SUITE, wasi_conformance_SUITE, wasm_rust_SUITEWASI preview 1, Changing the NIF
Componentswasm_component:instantiate/2, wasm_component:call/4, wasm_component:describe/1wasm_component, wasm_component_link, wasm_component_types, wasm_canon, wasm_resources, wasm_async, wasm_recipethe imports mapwasm_component:import_fun/2wasm_component_SUITE, wasm_component_describe_SUITE, wasm_component_custom_sections_SUITE, wasm_component_check_SUITE, wasm_component_link_SUITE, wasm_component_import_SUITE, wasm_component_iface_SUITE, wasm_component_resource_SUITE, wasm_component_string_SUITE, wasm_component_vectors_SUITE, wasm_component_version_SUITE, wasm_component_compose_SUITE, wasm_component_malformed_SUITE, wasm_component_async_SUITE, wasm_component_async_abi_SUITE, wasm_component_async_import_SUITE, wasm_component_async_tasks_SUITE, wasm_component_forward_SUITE, wasm_component_wast_SUITE, wasm_component_coop_threads_SUITE, wasm_canon_prop_SUITE, wasm_canon_check_prop_SUITE, wasm_resources_SUITE, wasm_recipe_SUITEComponents, Component internals
WASI 0.2wasi_preview2:imports/0, wasi_preview2:run_command/2wasi_preview2, wasi_p2_filesystem, wasi_p2_sockets, wasi_sock2the wasi_preview2 optionsnonewasm_wasi2_clocks_SUITE, wasm_wasi2_env_SUITE, wasm_wasi2_fs_SUITE, wasm_wasi2_in_SUITE, wasm_wasi2_io_SUITE, wasm_wasi2_iofull_SUITE, wasm_wasi2_random_SUITE, wasm_wasi2_sockets_SUITE, wasm_wasi2_tcp_SUITE, wasm_wasi2_udp_SUITE, wasm_wasi2_real_SUITE, wasm_wasi2_conformance_SUITE, wasm_wasi2_adapter_SUITE, wasm_wasi2_testsuite_SUITE, wasm_wasi2_p2_SUITE, wasm_wasi2_async_SUITEWASI 0.2
WASI 0.3wasi_preview3:run_command/3, wasi_preview3:run_serve/3wasi_preview3, wasi_p3_filesystem, wasi_p3_sockets, wasi_p3_httpthe wasi_preview3 optionsnonewasm_wasi3_p3_SUITEWASI 0.3
HTTPwasi_http:http/1, wasi_http_listener:start/1wasi_http, wasi_http_listener, wasi_http_transport, wasi_http_h1, wasi_http_h2http, http_authorize, http_transportthe wasi_http_transport behaviour, and the http_authorize hookwasm_wasi2_http_SUITE, wasm_wasi2_https_SUITE, wasm_wasi2_http_limits_SUITE, wasm_wasi2_serve_SUITEHTTP
wasi-nnwasi_nn:imports/1, the nn option of wasi_preview2:command/1wasi_nnnnthe wasi_nn behaviourwasm_wasi2_nn_SUITE, wasm_wasi2_nn_wasmtime_SUITEwasi-nn
Instance workerswasm_instance_worker:start_link/1, wasm_instance_worker:call/3wasm_instance_workerworker_timeoutnonewasm_worker_SUITEUsing workers
Actorswasm_actor:start_link/2, wasm_actor:send/2wasm_actor, wasm_actor_registrystart_link/2 optionsthe message type, chosen by the hostwasm_actor_SUITEActors
Script workerswasm_script_worker:start_link/2, wasm_script_worker:run/2wasm_script_worker, wasm_worker_adapter, wasm_worker_error, wasm_script_v1, wasm_worker_fs, wasm_worker_imagesworker options; scratch_rootsthe wasm_worker_adapter behaviourwasm_worker_kernel_SUITE, wasm_component_worker_SUITEUsing workers, Worker internals, Worker configuration
Worker cleanupinternal: every script worker request goes through itwasm_cleanup_manager, wasm_cleanup_steward, wasm_cleanup_steward_sup, wasm_worker_reaper, wasm_worker_supreaper_options, scratch_rootsnonewasm_cleanup_manager_SUITE, wasm_cleanup_steward_SUITE, wasm_worker_sup_SUITE, wasm_worker_kernel_SUITEWorker internals, then test/audit/CLEANUP_STEWARD.md
Language adapterswasm_script_worker:start_link/2 with an adapter modulewasm_javascript, wasm_javascript_command, wasm_python, wasm_python_command, wasm_lua, wasm_adapter_conformancethe adapter's optionsa new adapter, through wasm_worker_adapterwasm_worker_lang_SUITE, wasm_lang_SUITEHosting scripting languages, Writing an adapter
Build, packaging, the NIFrebar.config, scripts/c_src/WASM_NIF_SANITIZE, WASM_NIF_CFLAGSnonewasm_package_SUITE, wasm_scripts_SUITE, wasi_nif_SUITEChanging the NIF
These docsdocs/, the module docs, examples/nonerebar.config ex_docnonewasm_docs_SUITE, wasm_architecture_SUITE, wasm_examples_SUITECONTRIBUTING.md
Benchmarks and evidencebench/paths/, rebar3 benchnonenonenonewasm_bench_SUITE, wasm_gc_bench_SUITE (their bench group)Measuring, test/audit/PERF.md

Find the tests for a behaviour

Suites are named after what they test: wasm_<area>_SUITE for the runtime, wasi_<area>_SUITE for WASI preview 1, wasm_wasi2_<interface>_SUITE for WASI 0.2, wasm_wasi3_p3_SUITE for WASI 0.3 and wasm_component_<topic>_SUITE for components. Each opens by saying what it covers.

  1. Find the area in the table above and read its suites' headers.

  2. To find every suite that calls a module, search test/ for it:

    grep -l "wasm_heap:" test/*_SUITE.erl
    
  3. To find the case for one rule, search for a word of it. Case names are sentences, such as parent_traversal_is_refused:

    grep -n "traversal" test/wasi_SUITE.erl
    
  4. Run what you found, then the case alone:

    rebar3 ct --suite=test/wasi_SUITE --case=parent_traversal_is_refused
    

Some suites need a fixture or a tool and skip without it. Testing says which, and Fixtures how to get each one.

Read this next

Architecture for how the modules depend on each other and the path of one call, then the recipe for your change.