Repository navigation
feat(codegen-bun): intrinsics are first-class values - #864
Draft
hyperpolymath wants to merge 1 commit into
Draft
hyperpolymath wants to merge 1 commit into
hyperpolymath wants to merge 1 commit into
Conversation
Owner ruling 2026-12-01 ("First-class wrappers"). An intrinsic such as
`len`, `string_sub` or `trim` used as a value, not called, was emitted as
a bare name with no JS binding, so calling it threw a ReferenceError
(`let f = len; f(s)`; `apply(len, s)`). Declared externs were already
wrapped (#818). Non-extern intrinsics now are too.
- `builtin_arity`: each builtin's arity, read once from its type in
`Typecheck.register_builtins`. One source of truth, no hand-kept list.
- `wrap_builtin_value`: the lowering wrapped in an arrow of that arity.
It is shared with the #818 extern path, which now uses it, so there is
one wrapping rule. An awaiting lowering keeps the bare name, as #818
did.
Coverage:
- All 40 Bun builtins the type checker types are wrapped, and the new
suite fails if a typed builtin ever is not.
- The remaining Bun builtins are stdlib `extern fn`s, covered by #818.
- Two names, `acos` and `asin`, have a Bun lowering but are neither
resolvable nor typed, so no program can use them. That predates this
change and is reported in the PR.
Tests:
- tests/codegen-bun/intrinsic_values: len and to_uppercase passed to a
higher-order fn; trim, string_sub, string_find and int_to_string bound
with `let`. It fails on main with `ReferenceError: len is not defined`.
- test/test_intrinsic_values.ml: coverage, arity from type, and wrapper
text.
- dune runtest: 852 pass. Bun harnesses: pass. Ledger: ports #856's part
(main is red on property 3) and advances the stamp to 4a55253.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
|
Review these changes at https://app.gitnotebooks.com/hyperpolymath/affinescript/pull/864 |
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 1 minute. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Owner ruling 2026-12-01: first-class wrappers for intrinsics on Bun-ESM.
Problem
An intrinsic used as a value, rather than called, was emitted as a bare name with no JS binding:
Declared externs were already wrapped (#818). Non-extern intrinsics (
len,string_sub,trim,int_to_string, …) were not.Change
builtin_arity: each builtin's arity, read once from its type inTypecheck.register_builtins. That is one source of truth, with no hand-kept arity list.wrap_builtin_value: the builtin's lowering wrapped in an arrow of that arity, e.g.((__a0, __a1, __a2) => __as_strSub(__a0, __a1, __a2)).Coverage (measured)
test_intrinsic_valuesfails if any typed builtin ever is not.extern fns, which codegen(bun-esm): extern fn used as a value emits an unbound name #818 wraps when they are declared.acosandasinhave a Bun lowering but are neither resolvable nor typed (undefined value: acos), so no program can use them. Fixing that needs types and interpreter support, so it should be its own change.Tests
tests/codegen-bun/intrinsic_values:lenandto_uppercaseare passed to higher-order functions;trim,string_sub,string_findandint_to_stringare bound withlet.mainwithReferenceError: len is not definedand passes here.test/test_intrinsic_values.ml: coverage, arity from type, and exact wrapper text.dune runtest: 852 pass.run_codegen_bun_tests.sh: pass, including codegen(bun-esm): extern fn used as a value emits an unbound name #818's harnesses.check-soundness-ledger.sh: 5/5.dune build @fmt: exit 0. Governance: PASS.Ledger
mainis red on property 3. This ports the ledger part of #856, the same port as #862 and #863. It becomes a no-op once #856 merges.Relation to #862
#862 adds
char_to_string. Once both are merged,char_to_stringis wrapped like any other typed intrinsic, with no extra code.Generated by Claude Code