Repository navigation
Description
Summary
Add committed coverage for inline assembly parsing, unsafe enforcement, and LLVM lowering. The current compiler has an asm parser and LLVM bridge support, but the requirement campaign found no tests protecting the surface.
Spec
§16.13 says asm embeds target-specific assembly and requires unsafe context (docs/with-specification.md:8925). The full syntax is asm(template : outputs : inputs : clobbers), each section is optional, trailing sections may be omitted, templates are string literals, inputs/outputs are comma-separated bindings, clobbers are strings, and volatile marks side effects (docs/with-specification.md:8938).
Current state
Parser.parse_asm parses outputs, inputs, clobbers, stores input expressions and output type in extras, and emits NK_ASM_EXPR (src/Parser.w:4840). MIR lowering handles NK_ASM_EXPR extras (src/MirLower.w:7742). LLVM bridge exposes wl_get_inline_asm (src/compiler/LlvmBridge.w:1322). The missing piece is test coverage; #479 tracks target guards, not basic asm coverage.
Implementation plan
- Add parser/check tests for every syntactic form: template only, outputs only, inputs, clobbers, and volatile.
- Add negative tests proving asm outside unsafe context fails, malformed output/input constraints fail, and non-string templates fail.
- Add one host-gated behavior test if possible. On aarch64 Darwin, use a harmless instruction such as moving an input to an output; on x86_64, use an equivalent constraint. If target guards are not implemented yet, keep this as check/IR coverage rather than runtime behavior.
- Add an IR/codegen test path that checks generated LLVM contains inline asm for a simple fixture, avoiding reliance on optimizer details.
- Once @[target("arch")] architecture guards (§16.13) #479 lands, add target-guarded variants.
Test plan
Add test/spec/spec_ss16_13_inline_asm_parse.w for check-only syntax coverage. Add test/compile_errors/err_inline_asm_requires_unsafe.w, err_inline_asm_template_string.w, and malformed constraint tests. Add test/behavior/behav_inline_asm_basic_<arch>.w or an IR corpus entry if runtime execution is not portable.
Acceptance criteria
- All optional asm sections have parser/check tests.
- Unsafe enforcement for asm is tested.
- At least one codegen path proves
NK_ASM_EXPRreaches LLVM inline asm lowering. - Target-specific runtime tests are gated or deferred to @[target("arch")] architecture guards (§16.13) #479; no test should fail on a supported host just because it is a different architecture.
with build && with build :fixpoint && with build :testpass.
Dependencies
Overlaps #479 for target guards.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 16.13.1.1, 16.13.1.10, 16.13.1.2, 16.13.1.3, 16.13.1.4, 16.13.1.5, 16.13.1.8, 16.13.1.9.
Activity
ehartford commentedon Jul 3, 2026
Closing — asm clobbers section (behav_asm_clobbers) + non-string-template rejection (err_asm_template_string) pinned (3628d82); template-only/inputs/outputs/multi-output/unsafe-gate/unknown-placeholder already covered (behav_asm_literal_brace, behav_asm_placeholder, behav_asm_multi_output, err_asm_requires_unsafe, err_asm_unknown_placeholder). §16.
test: coverage-sweep batch 5 (#485 #486 #487 #500 #505 #510)