20261105 MoonBit v0.10.19 Release
moonc version: v0.10.19
Language Updatesβ
-
Derive syntax migration. Trait derivation moves from
derive(...)after a type definition to an attribute above it. Runmoon fmtto convert existing code. Attribute syntax no longer supports#foo(qual.id)and now supports#foo(@pkg.id)and#foo([elem1, elem2, elem3]).#derive(Debug, Eq, Hash) pub(all) struct Point { x : Int32 y : Int32 } -
Int/UInt renamed to Int32/UInt32.
Int32andUInt32represent 32-bit signed and unsigned integers. Explicit widths make code easier to read when several widths appear together, such as in binary protocols or FFI signatures.IntandUIntremain available as aliases, and both spellings can coexist in a project. The formatter can migrate the old spellings to the explicit-width names. -
Floating-point semantics. Arithmetic and comparison operators (
==,!=,<=,<,>=,>) continue to follow IEEE semantics.-0.0 == 0.0, andNaNis unequal to every value, including itself. The main change concernscomparewhen NaN is involved. Its results for NaN are currently unspecified. This mainly affects sorting and binary search, and NaN should not be used as a key in structures such as hash tables. Use the newFloat::total_compareorDouble::total_compareif you need defined comparison behavior for NaN. Both use the following order.NaN-Infinity- Negative numbers
-0.0and0.0, which compare equal- Positive numbers
+Infinity
-
Changes to extenum declarations. The old form combines the type declaration and its constructors in one definition.
extenum E { A }pub extenum E extenum E += { A } -
New byte regex literals,
reb"...". Usereb"..."with=~andlexmatchto matchBytesandBytesView, much asre"..."matchesStringandStringView. A byte regex matches bytes without encoding or decoding, so it can match arbitrary byte sequences. Its syntax is largely the same as that ofre"...". Capture types are determined statically by the regex. A capture that matches exactly one byte has typeByte, as inreb"." as b. Other captures have typeBytesView, as dobeforeandafter. In ordinary expressions, areb"..."literal has typeBytesRegex. LikeRegex, it can be assigned to a constant, combined with+and|, and referenced in patterns.fn parse_request(line : Bytes) -> Unit { if line =~ (reb"^(GET|POST|PUT) " + (reb"[^ ]+" as path), after=rest) { ... } } fn content_length(header : BytesView) -> BytesView? { lexmatch header { (reb"^(?i:content-length): " + (reb"[0-9]+" as n), after=_) => Some(n) _ => None } }- Only ASCII characters may appear directly in a literal. Use
\xHHfor non-ASCII bytes, including in character classes and ranges. Examples includereb"\xef\xbb\xbf"andreb"[\x80-\xff]+". Neither\u{...}nor direct non-ASCII characters are supported. For example, writereb"\xc3\xa9"forreb"Γ©". .and[^...]match any single byte, including 0x80β0xFF. Therefore,.matches only the first byte of a multibyte UTF-8 sequence.(?i:...),\b, and[[:word:]]use ASCII semantics. Bytes above 0x7F are neither case-folded nor treated as word bytes.
const HIGH : BytesRegex = reb"[\x80-\xff]" const HIGH_THEN_A : BytesRegex = HIGH + reb"a" - Only ASCII characters may appear directly in a literal. Use
lexscan currently does not support byte regexes.
-
Upcoming breaking change. In the next release, we will change the runtime layout of
Arrayon the JavaScript backend to align with the other backends.Arraywill no longer compile to a native JavaScript Array. -
Top-level
declare let. Declarations previously focused on interfaces such as functions and types. You can now declare a top-level value's name, type, and visibility withdeclare let, then provide a matching definition in the same package. This lets you review the package's public interface before deciding which file holds the value or how it is initialized.///| declare pub let default_limit : Int32 ///| pub let default_limit : Int32 = 100
Toolchain Updatesβ
-
Build static libraries with the Native backend. The following MoonBit program uses
#export_nameto specify an exported symbol. Setpkgtype(kind: "foreign_library")inmoon.pkg, then runmoon build --target nativeto produce an archive a host program can link. The output is an.afile, or a.libfile on Windows.let offset : Int32 = 2 #export_name("add") pub fn add(a : Int32, b : Int32) -> Int32 { a + b + offset }$ moon build --target native ~/playground/moonbit-playground/demo Finished. moon: ran 28 tasks, now up to date Artifacts: username/foreign/lib native path/to/_build/native/debug/build/lib/lib.a
On the host side, call moonbit_init() to initialize the MoonBit runtime.
#include "moonbit.h"
#include <stdio.h>
extern int32_t add(int32_t a, int32_t b);
int main(void) {
moonbit_init();
printf("add(40, 2) = %d\n", add(40, 2));
return 0;
}
Then compile the host program together with the static library generated by MoonBit and run it.
$ cc -I ~/.moon/include host.c path/to/_build/native/debug/build/lib/lib.a -lm -o host
$ ./host
add(40, 2) = 44
-
Migrate configuration in
.mbtxscript mode. A script can place configuration between---delimiters at the top of the file to keep dependencies and runtime permissions together. The header uses the configuration syntax ofmoon.pkgandmoon.mod. A script that needs a host environment variable can declare the requested permission here. Theimportsyntax continues to support aliases and import-all. An import can combine*with a package alias. In the example below, bothQueueand@q.Queuerefer to the same definition. With*alone, the default package alias remains available.--- import { "moonbitlang/core/queue" @q *, "moonbitlang/x/bcrypt", } --- fn main { println(Queue([1, 2]).length()) println(@q.Queue([3, 4, 5]).length()) } -
Generate
.mbtifiles automatically withmoon check. After a successful check,moon checkupdatespkg.generated.mbtifor the checked local packages whose preferred backend is included in the check. The file summarizes public types, functions, and traits, making API changes visible alongside source changes in code review. Runmoon check --no-mbtito perform type checking without updating these files. -
Documentation test improvements.
moon testalready supported extracting and testing code blocks inside///doc comments. We have improved extraction and parsing performance to make the coding-and-testing loop more efficient for agents using MoonBit. Test blocks no longer inherit the function's#cfgattribute. If a function supports only certain backends, add the appropriate#cfgmarker to the test block itself./// /// ```mbt check /// test { /// assert_eq(greeting("alice"), "hi, alice") /// } /// ``` fn greeting(name : String) -> String {...} -
Run test executables in parallel by default. Moon schedules test executables in parallel based on the available CPU count, reducing waiting time in projects with multiple test packages. Use
moon test -j 4to limit concurrency. For tests that share ports or external resources, usemoon test --no-parallelizeto run test executables sequentially while keeping the build parallel. This option does not affect concurrency among async tests within a single package. -
LSP support for
.mbtx. MoonBit language services can now handle.mbtxscripts, bringing editor support to standalone tools and automation scripts. -
Debug the new Native backend in VS Code. With the CodeLLDB extension installed and
preferred-targetinmoon.modset tonative, click the Debug button abovemainor a test to start debugging. Debugging is now available for the new Native backend in addition to the LLVM and JavaScript backends. -
Experimental
moon testclicommand. This command tests MoonBit command-line applications and.mbtxscripts and can replace the previouscramsubcommand. -
Major-version module paths. A module can use a path such as
owner/library/v{n}to identify a new major version. When publishing breaking changes, consumers can distinguish major versions through their paths. The default alias of the module's root package remains@library. Use explicit aliases when importing two major versions in the same code. Before MoonBit 1.0, publishing packages at version 1.0 or later is temporarily unsupported. -
Conditional imports. A package might use system libraries on Native and browser APIs on JavaScript. Use
#cfgto choose dependencies for each backend while keeping the same alias. If both implementation packages below providelabel(), call sites can use@platform.label()on either backend. The same mechanism applies to black-box and white-box test imports.#cfg(target = "native") import { "example/conditional/native_impl" @platform } #cfg(target = "js") import { "example/conditional/js_impl" @platform } -
Experimental package declarations. Declare a package experimental with
experimental = true. Direct consumers receive a warning, which they can suppress withallow-experimental-packages = true. -
Removal of legacy toolchain behavior.
- JSON manifests are no longer accepted. The
moon fmtmigration entry point remains available. moon installis no longer used to synchronize dependencies.moonxonly supports running Wasm programs.- Support for
bin-depshas been removed. Usemoonxinstead.moon add --binhas also been removed. - Automatic generation from
mblandmbyfiles is no longer supported. Usemoonxwith the corresponding libraries instead. - Versions specified in dependency declarations must actually exist.
- Using a core package without an explicit import now produces an error instead of a warning.
- JSON manifests are no longer accepted. The
Standard Library and Runtime Updatesβ
-
New
moonbitlang/core/asyncpackage. It includes all the functionality ofmoonbitlang/async, with corresponding packages such asmoonbitlang/core/async/httpformoonbitlang/async/http. In the future,moonbitlang/core/asyncwill become the default asynchronous runtime, andmoonbitlang/asyncwill be gradually deprecated. For now,moonbitlang/core/asyncis experimental and its APIs are still evolving. To use it, add"allow-experimental-packages": trueto theoptionssection ofmoon.pkg.Its APIs include substantial improvements overmoonbitlang/async. Once they stabilize, we will provide a detailed migration guide.moonbitlang/core/asyncandmoonbitlang/async@0.22.7+can coexist in one program, allowing applications to migrate incrementally. -
Path utilities join the standard library. Import
moonbitlang/core/pathfor basic file-path operations. As shown in the.mbtxscript below, the package can extract a path's extension, filename, and parent directory. It also supports joining path components with/.--- import { "moonbitlang/core/path", } --- fn main raise { let file1 = @path.Path("path/to/base/file1.mbt") assert_eq(file1.extname(), ".mbt") assert_eq(file1.basename(), "file1.mbt") let base = file1.dirname() let target = base / "fixture" / "file2.txt" assert_eq(target, "path/to/base/fixture/file2.txt") } -
Compression and ZIP archives.
core/compressadds raw DEFLATE, gzip, and zlib codecs, whilecore/archive/zipadds ZIP and ZIP64 support. Choose the corresponding standard-library package to process gzip data, create ZIP files, or read archive entries. The archive API also exposes entry metadata, so you can inspect the contents before deciding which entries to read. -
Support for using
moonbitlang/core/abortas a virtual package has been removed. -
The
Jsontype andToJsontrait have moved tomoonbitlang/core/json. Some built-in types no longer support calls in the forma.to_json(). UseToJson::to_json(a)orJson(a)instead. -
moonbitlang/x/timeimproves support for reading TZif (Time Zone Information) files and adds access to the system's current time zone, currently on the Native and JavaScript backends.
Ecosystem and Developer Tool Updatesβ
-
mooncakes.io improvements.
- Added registration, sign-in, and password recovery, and added dependents to documentation pages. Skill uploads are now separate from module uploads.
- Improved search results so modules matching by name consistently appear first.
-
SeekMoon.
- Added a Conversations page, allowing SeekMoon to be used without attaching a workspace.
- Added cloud agents. Sign in, then create a conversation on the Conversations page to use them.
- Added image support. Paste images directly into the input box, or let the agent read images through a tool.
- Added scheduled tasks, which can be created from the sidebar.
- Integrated Word, Excel, and PDF previews. SeekMoon can now generate PDFs with Typst and preview them.
- Added built-in
/ultrareviewand/simplifyworkflows, which launch multiple subagents concurrently for code review and codebase simplification. - Added local pull request review. Open the GitHub page from the sidebar to browse a repository's pull requests and view GitHub review comments at the corresponding file locations.
-
Two new command-line tools are available through
moonx cli/typstandmoonx cli/rg.




