Contributing to Moxy
Bug reports, test cases, docs fixes and patches are all welcome. This page says how to build the project, what a good change looks like, and what to do before you start something large.
Build and test
You need a C compiler, make, and the goose submodule:
git clone --recursive https://github.com/moxylang/moxy.git
cd moxy
make # build/moxy, bootstrapped from bootstrap/moxy.c
make test # the suite in tests/ plus the examples
make verify # build/moxy must reproduce its own generated C
If you cloned without --recursive, run git submodule update --init libs/goose.
The compiler is written in Moxy and compiles itself. make verify is the check that matters most: if your change alters what the compiler generates for itself, it must reach a fixed point.
CI also runs these. Run them yourself before you send a change:
make sanitize && ./build/asan/moxy test --sanitize tests # if you touched runtime/ or code generation
./build/moxy fmt --check tests examples std tools bench
make budget # after make test: sizes, memory, threads, cache (needs bun)
A change that makes a budget in bench/budget.json worse on purpose updates it (bun bench/budget.ts --update) in the same commit and says why. If you touched the runtime's tasks, fibers, channels, actors or std/net, also run the soak workloads for a while: make soak SOAKMIN=30 (bun again) should end with every series flat. How the soak judges, and how to run one for hours, is in Architecture.
If you touched the lexer, parser, checker or code generation, a few minutes of fuzzing is worth it (make fuzz; it needs bun and a clang with libFuzzer). Fuzzing covers longer runs and turning a finding into a test.
The compiler and sanitizer matrix
scripts/matrix.sh runs the suite (tests/, the test blocks in std/ and examples/*.mxy) once per C compiler, optimization level and sanitizer, and prints a table of passes per cell:
sh scripts/matrix.sh # every compiler found, -O0 and -O2, none/address/undefined/thread
sh scripts/matrix.sh --cc gcc --opt O2 --san thread # one cell
sh scripts/matrix.sh --cc mine=/opt/cc/bin/clang # a compiler by path
sh scripts/matrix.sh --cc "x64=x86_64-linux-gnu-gcc -static" --san none,undefined # another architecture, under qemu-user
The compilers it looks for are Apple clang, Homebrew LLVM clang and zig cc on macOS, and gcc, clang and zig cc elsewhere. Every cell must meet the same .out, .code and .stderr expectations; an example must print what the first compiler's plain -O0 build printed. Cells are debug builds (-DMXY_DEBUG=1, so -O2 keeps the overflow checks and the leak report). A sanitizer report fails its test with exit status 86. A sanitizer a compiler doesn't support shows as n/a. -j sets how many cells run at once (4 by default); a whole run takes a while, so pick cells with --cc, --opt and --san while working on one failure. Logs stay in the directory printed at the end (--out to choose it).
A test whose output differs between cells is usually relying on something C leaves open, such as the order a call's arguments are evaluated in; make the output independent of it rather than accepting one order. Under qemu-user, ASan and TSan don't start, UBSan's runtime can fail its own checks, and a missing program passed to posix_spawn looks like a successful spawn, so those failures there aren't the program's.
Suppressions live in scripts/matrix/, one file per sanitizer, and each entry says why the report isn't a bug. Add one only for that reason; fix the code otherwise. CI runs the matrix on Linux x86_64 and arm64 (gcc and clang), macOS (Apple clang), zig cc, and Windows (MinGW gcc, -O2, no sanitizers).
Compiler internals maps the source tree, and Architecture explains the pipeline.
Two rules about the compiler's own source
- Don't use a language feature in
src/that the committed bootstrap doesn't know.makebuilds the compiler frombootstrap/moxy.cfirst, and an older bootstrap can't parse newer syntax. A new feature lands in the compiler first and is used insrc/only after the bootstrap is refreshed. - Don't edit
bootstrap/moxy.cby hand. Maintainers refresh it withmake seedaftermake verifypasses. Leave it out of your change.
Making a change
- Open an issue first for anything that changes syntax or semantics. Those go through the language change process. Bug fixes, diagnostics, tests, docs and tooling don't need a proposal.
- Keep it small and focused. One change per pull request. Don't mix a fix with a reformat.
- Add a test. Every behavior has a test. See below.
- Keep generated C readable. If a change makes the output harder to read, say why in the description.
- Don't promise what isn't tested. Docs describe what exists and what a test covers.
Tests
Tests live in tests/, one directory per area. A test is a .mxy file with a main, plus optional files next to it:
Next to name.mxy |
Meaning |
|---|---|
| nothing | passes if it exits 0 (use assert) |
name.out |
standard output must match exactly |
name.code |
expected exit code (for example 101 for a panic) |
name.err |
compilation must fail with each listed message |
name.warn |
compilation must succeed with each listed warning; an empty file means no warnings at all |
name.stderr |
standard error must contain each listed line (with name.code, checks a failed assert or a panic) |
name.fix |
moxy fix must print exactly this diff and these suggestions, and the fixed program must pass the same checks |
A test also fails if its program prints the debug leak report (ref objects still alive when main returns).
A small check of one function can instead be a test "name" { ... } block next to it, or a ```moxy example in its doc comment; moxy test runs both. See Testing.
A new diagnostic needs a failure test: tests/fail/<name>.mxy with the expected message in <name>.err. Run one test with ./build/moxy test tests/strings/split.mxy.
Style
- Source files are small and focused: one concern each. A module is a directory whose
index.mxydeclares its types and includes the rest. - File and directory names are lowercase, with no spaces, dashes or underscores (language- or tool-mandated names such as
Makefileexcepted). Preferdir/{index,part}.mxytodir-part.mxy. - Run
moxy fmton.mxyfiles you touch. CI checks it. - Comments say why, not what.
- Commit messages are plain and descriptive: what changed and why, in the imperative. No issue-tracker boilerplate.
Where things go
| Change | Start in |
|---|---|
| a builtin method | src/sema/method.mxy, src/gen/call.mxy, a runtime/*.h function if needed |
| a diagnostic | diag_error / diag_hint at the check, plus a tests/fail test |
| a standard library module | std/<name>.mxy |
| a runtime function | runtime/*.h as MXY_FN |
| the formatter | src/fmt/ |
| docs | docs/; the site is built from it (site/) |
The longer version of this table is in Adding things.
Finding something to work on
docs/starter.md lists small, concrete tasks with the file and line to start from. The roadmap shows what is planned; check with the maintainers before picking up a roadmap item, since several depend on each other.
Reporting bugs
Include the .mxy file (smaller is better), the command you ran, what you expected, and what happened. For a miscompile, include the output of moxy emit file.mxy around the part that is wrong. For a crash in the compiler itself, say so, and give the output of moxy --version.
Security problems: email the maintainer rather than opening a public issue.
License
By contributing you agree that your work is released under the MIT license.