Skip to content

Make builtin.abort virtual #3239

@applejag

Description

@applejag

Is your feature request related to a problem? Please describe.
I want to optimize for binary size.

The builtin.abort() uses formatted string and SourceLoc, which brings in ~5kB when compiled to WASM. As builtin.abort() is used a lot throughout the core library then it's really hard to avoid it.

#callsite(autofill(loc))
pub fn[T] abort(string : String, loc~ : SourceLoc) -> T {
@abort.abort(
(
$|\{string}
$| at \{loc}
$|
),
)
}

Describe the solution you'd like
MoonBit has virtual packages. Could builtin.abort() be moved into a virtual package? Or could the formatting and SourceLoc be moved to the abort package as it's already a virtual package?

core/abort/abort.mbt

Lines 26 to 30 in d3224da

#cfg(not(target="native"))
pub fn[T] abort(msg : String) -> T {
let _ = msg
panic_impl()
}

Describe alternatives you've considered
I've tried overriding abort package as suggested in moonbitlang/moon#1369, but that doesn't remove the string formatting and SourceLoc code as that code lives in builtin.abort()

Additional context
When using MoonBit on embedded devices (e.g Firefly Zero) then binary size is very important, where +5kB is a lot. For the Firefly Zero use case we also use Bytes a lot instead of String as the FFI requires UTF-8, and so we don't want to include the string-related code in the final build.

  • I do think that this should be part of the core library and should be delivered to all the MoonBit developers.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions