Repository navigation
v0.8.0
Added
- Monomorphic type system — total static type checking. Every Wavelet
expression now has a WIT type, decided by a static checker pass (src/check.rs)
that runs on every path —wavelet run,wavelet build,wavelet wit,
and the playground — before any code runs or any component is emitted. Checking
is total: an ill-typed definition is a compile error even when nothing calls
it, so type errors surface at build/run/wit time rather than at the wasm
boundary. Inference is bidirectional — types propagate inward from contexts
(function signatures,Letbindings,Matchresults) and synthesize outward
from atoms and applications. - Numeric-literal resolution + defaulting, and
Theascription. A bare
numeric literal takes its type from context and is range-checked against it
(The u8 300is a compile error); with no context it defaults tos64
(integers) orf64(fractionals). TheTheform ascribes a type to an
expression (The s64 5), both to pin a literal and to drive resolution where
arguments alone don't decide. - Ad-hoc overloading. Several monomorphic
Defs sharing a name form an
overload set. Each call site is resolved statically: first by the WIT types
of its arguments, then — when arguments don't decide — by the expected return
type supplied viaThe. An exported overload set is name-mangled at the
component boundary so each concrete instance gets a distinct WIT export
(e.g. aneqoverpointis exported aseq-point). Derive {Eq Ord Show Hash} t. Derives the standard operations for a type,
expanding to concrete monomorphic definitions (e.g.eq-point,show-point)
whose WIT signatures are synthesized like any other export.- Functor instantiation via
Import {pkg: … elem: t as: …}. A parameterized
import specializes a generic interface to a concrete element type, synthesizing
a per-element WIT interface (e.g.setinstantiated atpointyields a
concretepoint-setinterface) — nothing generic survives into the emitted
world. - Macro components — run macros defined in other components.
Import {pkg: "…" macros: true}imports a macro library: a component exporting
wavelet:meta/macros@0.1.0(manifest()→(name, arity)pairs,expand(name, args)→result<tree, string>). Wavelet instantiates it at compile time,
registers its macro arities with the reader (so foreign TitleCase macros read
paren-free, top-to-bottom, like localDefMacros), and routes expansion
through the component'sexpandto a fixpoint (design.md §6.2–§6.3). The
library's.wasmis resolved from an explicitfrom:path or the conventional
wit/macros/<ns>-<name>.wasmlocation. Amacros: trueimport is
compile-time-only: it is excluded from the synthesized runtime world, so the
shipped component never importswavelet:meta/macros. Because a macro library
is an ordinary component, macros can be written in any language that compiles to
one, and they run sandboxed by construction. - Qualified and aliased foreign macros. Imported macros are available both
bare (Element) and qualified by the import alias (dsl/Element, with
as:). A bare TitleCase name provided by two imports — or by an import and a
localDefMacro— is ambiguous and errors only when used bare, with a
message suggesting you alias or qualify; the qualified spelling always
resolves. - Build-time component runtime. Running foreign macros at compile time needs
a wasm runtime, so the compiler now depends onwasmtime(native targets
only). It is gated out of thewasm32build: the browser-playground bindings
moved behind a new default-onplaygroundcargo feature, so the
wasm-compiled interpreter (and the macro-library guest) build without
wasmtimeorwasm-bindgen. The playground therefore has no component
runtime — foreign-macro examples run only in nativewavelet build, not in
the browser. - Produce macro components from Wavelet (
wavelet build). A.wvlfile
whose top level is aPackagedeclaration plusDefMacros only (noExport,
no runtime defs) now compiles into a component exportingwavelet:meta/macros,
so a macro library can be written in Wavelet itself and imported with
Import {… macros: true}like any other macro component (design.md §6.3). Each
macro body is compiled to wasm (the compiler learned to emit
Quote/Quasi/Unquote/Splice,gensym, and the form-introspection
builtins), so the produced component carries no interpreter and is built
in-process — nocargo, nowasm32-unknown-unknowntarget. The interpreter
remains the differential oracle the compiled expansions are checked against.
Changed
- Macro expansion is compiled, not interpreted (native build). A file's
localDefMacros and produced macro libraries now expand through a compiled
wavelet:meta/macroscomponent rather than the tree-walking interpreter, so
wavelet build/wavelet expandno longer interpret macros. Macro builds are
faster and need nowasm32-unknown-unknowntarget. The browser playground
keeps expanding local macros with the in-browser interpreter (it has no
component runtime); the interpreter also stays as the differential oracle.
Fixed
- The type checker now runs on
wavelet run,wavelet build, and
wavelet wit, not only the playground. Previously the checker (and, on the
run path, overload resolution) was wired into the playground evaluator alone:
wavelet runbound same-namedDefs by last-wins shadowing — so an overloaded
call reached whichever def was read last and failed or silently ran the wrong
body — andwavelet build/wavelet witemitted/synthesized ill-typed programs
without complaint. Each of these paths now type-checks the (expanded, for
build/wit) program first, so an ill-typed program is rejected everywhere and an
overloaded call dispatched throughwavelet runresolves to the correct member. - Compiled
add/sub/mul/div/rem/negandlt/le/gt/genow
match the interpreter on floats and strings. The wasm backend previously
unboxed every operand as an integer, so a compiled component that didf64
arithmetic or comparedstrings built cleanly but trapped at runtime. These
builtins now dispatch on the operand at runtime: arithmetic doesf64math
when an operand is a decimal (widening integers in mixed operands), and the
comparisons order strings lexicographically and numbers asf64— the same
results the interpreter (the semantics oracle) produces. - Compiled arithmetic is strictly binary.
add/sub/mul/div/remin a
compiled component now require exactly two arguments, as the interpreter
already did, instead of silently folding three or more. - Compiled integer overflow is checked.
add/sub/muloverflow and the
div/remedge cases (divide-by-zero,INT_MIN / -1,INT_MIN % -1) now
trap in a compiled component, matching the interpreter's checked-arithmetic
errors instead of wrapping. -infis matched as a whole word. The lexer no longer splits a longer
token beginning with-inf(e.g.-info,-infinity) into-infplus a
trailing fragment, mirroring the whole-word match the positiveinf/nan
literals already used.wavelet runreports a missing entry point. Running a file with no
no-argumentrunclosure now prints an actionable error instead of silently
doing nothing.u64parameters reject negatives. The interpreter's dynamic type check for
au64parameter now rejects negative integers, consistent with theto-u64
builtin.- Overload name-mangling at the WIT boundary is no longer over-broad and emits
legal WIT. Exporting an ordinary library-named function defined once (e.g.
get,head,map,concat,to-string) is no longer treated as a
one-member overload set and name-mangled; only a genuine ≥2-member overload set
or one of the curated overloadable operations (the derivableeq/compare/
show/hashand the comparison/arithmetic operators) triggers mangling. The
mangled suffix is also now an identifier-safe WIT label: a constructor-typed
first parameter such aslist(s32)produceseq-list-s32rather than the
illegaleq-list<s32>. - Overload mangling no longer collides on members that differ only past the
first parameter. The mangled WIT label was derived from the first parameter
type alone, so two members likeeq {a: point b: string}and
eq {a: point b: s32}both becameeq-point— two functions of the same name
in one interface (invalid WIT). When the first-parameter labels are all
distinct they are kept unchanged (soeqoverpoint/stringstays
eq-point/eq-string); when any collide, the whole set is disambiguated over
all parameter types (eq-point-string,eq-point-s32). A genuine duplicate
(two members with identical parameter type lists) is now a clear compile error
naming the export instead of emitting invalid WIT. - A
Derived op's auto-export no longer collides with an explicit
re-export.Deriveauto-emits a bareExport {op}-{t}for each derived
operation, so writing that sameExport eq-pointyourself (a derived op is an
ordinary exportable function) declared it twice and synthesized a duplicate
eq-pointWIT function. Identical export declarations — same exported name and
same explicit signature — are now collapsed to one before WIT synthesis;
declarations that share a name but differ in interface or signature are kept. - An ordinary
Importcarrying anelem:field is no longer hijacked as a
functor. Functor instantiation is now classified by the import's package
identity, not by the presence of anelem:field: only anImportwhosepkg:
is a known functor package (currentlywavelet:coll/set) is read as a functor.
Any other import that merely happens to useelem:(e.g.
Import {pkg: "acme:widget/thing" elem: point as: w}) stays an ordinary import
with the unknown field ignored, instead of erroring withunknown functor package. A known functor package missing itselem:is still a clear error. wavelet witnow expands macros before synthesizing the world. Thewit
subcommand synthesized straight from the read forms without running expansion,
soDerive(and any foreign macro) never ran on thewitpath: a program that
wavelet buildcompiles failed underwavelet witwith e.g.Export eq-point has no definition.wavelet witnow runs the same foreign-macro-aware expand
pipeline aswavelet build/wavelet expand, so the two subcommands agree about
the same source.- An exported overload set now builds to a component.
wavelet wit
synthesized a mangled WIT export per overload member (eq-point,
eq-string, …) and the interpreter resolved the set, butwavelet build
failed withexporteq-pointhas no Def Fn: the emitter keyed its internal
functions by the members' shared original name (eq), which collapses
last-wins, so the export wrappers — which look bodies up by the mangled name
— found nothing. The emitter now records the exact(params, body)each
mangled export was synthesized from and emits one concrete internal function
per member keyed on that identity, so a single curated-op overload export
(Def eq Fn {a: point b: point} true+Export eq) and a genuine multi-member
overload set both componentize.
What's Changed
- feat: run macros defined in other components by @logaan in #12
- docs: plan for replacing the interpreter with the compiler by @logaan in #14
- Compile macros to wasm (strategy A → B): replace-interpreter Step 1 by @logaan in #16
- docs: compiler implementation review (review.todo.typ) by @logaan in #13
- docs: design doc for Wavelet's monomorphic, WIT-bounded type system by @logaan in #18
- Fix compiler-review findings: backend numeric parity + robustness nits by @logaan in #17
- test(type-system): TDD plan for the monomorphic type system by @logaan in #19
- feat(type-system): implement the monomorphic type system (Steps 1–12) by @logaan in #20
- release 0.8.0 by @logaan in #21
Full Changelog: v0.7.0...v0.8.0