How to pull code and tests from the maxon repository (c:\Users\Eric\Dev\maxon) into minimaxon with cmd/convert. Use when bringing a stdlib file, a self-contained maxon-bin piece or a spec test into self/ or the corpus, when triaging convert warnings, or when changing cmd/convert itself.
Install
npx skillscat add maxon-lang/maxon-rewrite-bootstrap/convert-from-maxon Install via the SkillsCat registry.
Converting from maxon
Maxon code and tests come through cmd/convert, not by hand (plan, "Reuse"). The converter rewrites maxon's syntax and
layout into minimaxon's and marks what minimaxon cannot say. Where a piece is not converted it is still the reference
for behaviour, edge cases and names, unless the difference is a deliberate change recorded in README "Where it differs
from Maxon".
Converted files are regenerated from the maxon repository and never hand-edited. A needed change goes to the tool (or,
for a missing feature, to self/), then the file is regenerated.
Graduation. Conversion is part of implementing a file, not an ongoing process. When a converted file of stdlib/ is
complete (it has every name of maxon's file that minimaxon can have, and what its specs still fail is outside it) it
graduates, one group directory at a time: write graduated at the end of its line of stdlib/files.txt. From then on the
file is hand-edited and the regeneration (stdlib.ps1, gate stdlib, the gate's "library regenerates") neither converts,
writes nor compares it; keep its line in the listing, since cmd/convert/visibility.go reads the listing as the files
converted and present, and a file that left it makes the files still converted over-export. Landing a graduation also
deletes each conversion rule keyed to a type or function name whose last converted user has graduated (with its Go test),
and the docs that describe it (README "The standard library", AGENTS.md); prove the library's IR is unchanged (build <program> --emit-ir before and after, on a program that reaches every module of the group) and that gate specs loses no
test. A file that was split by stdlib/split.txt graduates with its other half (String.maxon: text/string/String.maxon
and core/String.maxon; Array.maxon: collections/array/Array.maxon and core/Array.maxon; FilePath.maxon: system/filepath/FilePath.maxon andcore/FilePath.maxon; Subprocess.maxon: its Pid went to system/process; the routes stay in the table as the record of the
layout, and no run reads it any more: cmd/convert --split went with the last file that had a route), and a side file that only existed to survive the
regeneration is folded into the file of the type it extends (String's Comparable and iterator in core/String.maxon,split in text/string/String.maxon, trim by a CharacterSet in text/characterset/CharacterSet.maxon, Array'sCloneable and element-wise equals in core/Array.maxon, TcpClient's keepalive, readiness and sending innet/net/TcpClient.maxon, TcpListener's readiness in net/net/TcpListener.maxon and Pid, the side file that the split ofSubprocess.maxon wrote to system/process, in system/process/Process.maxon), with every declaration and comment. A helper file that only
the graduated group's modules use graduates with it (_helpers/slotScan.maxon, used by map and set). A generated file
of a graduated group (crypto/curves/CombTables.maxon) stays generated and
compared. Never convert a graduated file again: to bring in what maxon changed, read maxon's file and edit the graduated
one. To find the rules that a graduation leaves without a user, build cmd/convert with go build -cover, run it withGOCOVERDIR over the files that stay converted and over the spec conversion, and again over the files that graduate: what
only the second run covered is dead once they have graduated. Coverage sees code, not the entries of a table (a name inextendedBuiltinRecords, extendedBuiltinEnums, builtinParamTypes, localsHidingModules, fileEndings, which went with File.maxon, FilePath.maxon and HeapStats.maxon, as did dropUnprovidedMembers and the tables of the built-in's methods and of the library's raw members that only it read (builtinMethods, libraryRawMembers, which builtingen wrote); the rule that exported a helper's public and kept the codec's names public went with httpHelpers.maxon, and Process of extendedBuiltinRecords and the rule that left out a conditional region of built-in names (maxon's ExitCode) with Process.maxon; renameBesideBuiltins (the file's side of the Mx prefix), namesHidingModules (a field named stream is which) and the toString().cstr() of a path went with Subprocess.maxon, while the program's side of the prefix, typeNamesHere, rewriteWithIterator and spawnedTypeAfter stay for the spec conversion): search cmd/convert for each name the graduating files
declare, delete the entries, and prove that converting what stays (each file of files.txt that has not graduated, with--listing) and the spec conversion (--specs) write the same bytes before and after, (an entry the spec conversion needs stays:CivilDate of unsupportedExtensionTargets, typeNamesHere, and, found by turning each off and comparing the spec conversion,rewriteFileBuffers with fileCallLabels and dropRawBufferCasts). A rule that coverage finds no user of but that is not keyed to a name
(dropBuiltinDeclarations, dropLiteralMarkers, the cases of visibility.go) is a general rule of the tool and stays. The groups crypto/, text/ andcollections/ have graduated, and so have the files at the library's root (the core's Interfaces.maxon, Hash.maxon,Hasher.maxon, PrimitiveExtensions.maxon and StringHash.maxon, _helpers/ByteOrder.maxon and math/Math.maxon), and
the complete files of system/ (Clock.maxon, Sleep.maxon, Directory.maxon, Process.maxon, Subprocess.maxon,osErrorCodes.maxon, fileWriter.maxon), and net/ (urlHelpers.maxon, URL.maxon, TcpClient.maxon,TcpListener.maxon, httpHelpers.maxon), and so have File.maxon, FilePath.maxon (with core/FilePath.maxon,
the core's half) and HeapStats.maxon of system/, and maxon's helpers/string/unicodeCategory.maxon and helpers/string/grapheme.maxon (intext/characterset and text/unicode; the generated unicodeCategory_gen.maxon that the first replaced is gone): HttpClient.maxon of net/http/ and the TLS helpers of net/tls (maxon's helpers/tls) have graduated too: what is still
converted is Testing.maxon, of which only TestFailure is kept (providedDeclarations). split.txt's routes of the graduated
files (String.maxon, Array.maxon, FilePath.maxon and Pid out of Subprocess.maxon) stay as the record, and nothing reads them. A rule can have a user that coverage of the files only shows when
the spec conversion is run too (dropBufferCStrings, which Process.maxon needed and a spec test still does, andrewriteWithIterator, which Subprocess.maxon needed and FilePath.maxon and many spec tests still do): run both.
Running the tool
Go may not be on PATH; it is at C:\Program Files\Go\bin. The tool lays out what it converts with the compiler'sfmt, so build bin\minimaxon.exe first (.\build.ps1), or name a compiler in the environment variable MINIMAXON. Run
from c:\Users\Eric\Dev\minimaxon:
go run ./cmd/convert --out=C:\temp\conv C:\Users\Eric\Dev\maxon\stdlib\Math.maxon # one file, to a scratch dir
go run ./cmd/convert --check C:\Users\Eric\Dev\maxon\stdlib # each warning kind, its count and filesstdlib/ as a whole, but for the files that have graduated, is regenerated from stdlib/files.txt by .\stdlib.ps1 C:\Users\Eric\Dev\maxon\stdlib (on Linuxgo run ./cmd/gate stdlib <maxon's stdlib directory>): it converts each listed file into its module (the module's directory
under stdlib/, group directory included: crypto/chacha), then runs the
compiler's fix over stdlib/. gate stdlib --check <directory> (the gate's step "library regenerates" whenMAXON_STDLIB names it) fails when the regeneration differs from what is committed, so a change to cmd/convert
regenerates and commits the library in the same change.
(Build it once with go build -o <scratchpad>\convert.exe ./cmd/convert for repeated runs; keep the exe out of the repo.)
- Input: files or directories (directories are walked for
*.maxon, skipping dot-directories, sorted by path). No path or-reads stdin and writes stdout. A single file with no flag writes stdout. --out=DIR(or-o DIR) writes each file toDIR/<path relative to the given directory>, creating directories.
Several files need--out,--writeor--check.-w/--writerewrites the input in place. Never point it at the maxon repository; it is for files already in
minimaxon (for example a file converted earlier that the tool now converts differently).--checkwrites nothing and exits 1 if any file would change or warned (exit 2 is a usage error). It cannot be
combined with--writeor--out. On stdout it prints one line per kind of warning (its message): the count, the
number of files it appears in, then the message, most frequent first, and last how many files would change. Each
warning still goes to stderr, so2>$nullleaves the summary, the list of what blocks the most files.- Warnings go to stderr as
file:line: warning: message; the same message is left in the output as an inline// TODO: messagecomment on that line, so a converted file shows what blocks it. - The output is passed through the strict formatter (
syntax.Format). If the formatter rejects it, the unformatted
candidate is written (Result.Formattedis false); treat that as a failure to fix in the tool, not as a file to keep. - Without
--specsthe tool handles.maxononly;--specsconverts maxon's spec files (see "Spec tests").
Where outputs go
- A stdlib file or a self-contained
maxon-bin/piece goes underself/<package>/(for example the PE writer and x64
tables toself/backend/, the diagnostic messages toself/diag/,stdlib/Map.maxonin place ofself/table/). - Runtime pieces (the command-line splitter, UTF-16 conversion) go to
runtime/. maxon's emitter form (maxon-bin/Compiler/Runtime/*.maxon) must be
rewritten into plain runtime source, so convert, then adapt in the tool or the compiler, not in the output. - Convert into a scratch directory with
--out, read the warnings, and copy intoself/only a file that converts
without a warning (or whose warnings are all for features the plan lands before that package is used).
Recording where a file came from
Name the maxon source file in the commit message.
Triaging warnings
Each warning is one of two kinds. Decide per message, not per file.
- A feature minimaxon lacks. The messages say "not supported in minimaxon": floats, tuples, closures,
default parameters,static let,testdeclarations,#if, union errors,default throws,if try, a block
handler (otherwise (e) 'label') inside brackets, iteratorforloops, byte strings,CharacterSetand a trim of one, format
specifiers, array/map literals, capabilities,extends, and so on. README "Where it differs from Maxon" lists what
minimaxon still lacks and what it spells differently on purpose; the converter rewrites the second and warns of the
first, and nothing else. Leave the file out, or skip
that test, until the feature lands inself/'s plan. Do not hand-edit the TODO away. - A rewrite the tool should do. The construct exists in minimaxon in another form, or the tool misses it: a
reserved word used as a name ("rename it"), a layout the formatter rejects, a shapeconvert_test.godoes not
cover. Fixcmd/convert, rungo test ./cmd/convert, then regenerate. Add aconvert_test.gocase only when the
construct is not covered or the bug would come back.
Many files that get a warning for the same construct mean a tool fix, not many edits.
Stage 1.2a realigned minimaxon with maxon: the syntax (implements, bare alias type arguments, quoted labels,panic of a string, keyword argument labels), error throws, try ... otherwise, the built-in names and the
module visibility all match, so the tool neither rewrites nor warns about them. When a stage lands a feature or changes
a spelling, re-run --check over stdlib and remove the rule or the warning for what now matches; a warning for a
feature that works is a bug in the tool.
--check over a whole tree is the to-do list: its summary shows which missing feature blocks the most files. After
converting a multi-module project, run minimaxon qualify <dir>: the tool works one file at a time and leaves another
module's names bare as Maxon writes them, where minimaxon requires them qualified.
Spec tests
maxon's tests are c:\Users\Eric\Dev\maxon\specs\*.md (664 files, 17,649 tests). Each is front matter, prose, then a## Tests section of <!-- test: name --> followed by optional directive comments, a ```maxon block (several
files when it holds // --- file: markers) and its expected result in ```exitcode, ```stdout,```stderr or ```maxoncstderr (a compile error, with <fragment>:L:C positions) blocks. The format is
maxon's docs/SPECS.md.
specs/ holds them converted, regenerated from maxon, never edited. From the repository root:
Remove-Item specs\*.md -Exclude README.md; go run ./cmd/convert --specs --out=specs C:\Users\Eric\Dev\maxon\specs
go run ./cmd/convert --specs --check C:\Users\Eric\Dev\maxon\specs # what blocks the rest, without writing--specsconverts each test's```maxonblock (each// --- file:section of it) through the source
conversion and copies everything else, with line endings made LF. A file with no test (maxon'sAGENTS.md) is left out.- The marker. A test whose conversion warned, or whose source minimaxon cannot parse (and whose expectation is not a
syntax error, which is then the point of the test), gets one<!-- skip: kind -->line per kind of warning right after
its<!-- test: ... -->line. The kind is the warning's message, orminimaxon does not parse the converted source:
and the parser's message. The runner skips and counts a test that carries the line, and runs every other test. Existingskiplines in an input are dropped and regenerated. - The warnings are not printed one by one (there are tens of thousands); each is a
// TODO: messagein its test. The
summary, which--checkand a conversion both print, is one line per kind: the number of tests it blocks (a test
counts under each of its kinds), the files, the kind, most blocking first, thenN tests: C converted cleanly, S skipped. - Triage as for any file: a feature minimaxon lacks is left (its tests stay skipped until it lands); a construct with
an equivalent is rewritten by the tool, which regeneratesspecs/. minimaxon.exe test specsruns them (README "Tests"). Until Phase 3 no script runs them all:.\check.ps1runs
only the tests not inspecs/passed.txt, andspecs.ps1adds the new passes to that list. The positions in amaxoncstderrblock are
authored against maxon's layout of the block, which the conversion changes (blank lines, indentation), so such a
test carries<!-- positions: moved -->and the runner compares codes and messages only.
Finish
Before a commit, .\check.ps1 passes: it formats and applies go fix first, then runs every check and stops at the
first failure. Commit only when asked, on main. A change to what cmd/convert does updates the README line that describes it.