Repository navigation
Conversation
Changelog🏠 Internal
Semantic Diff1 commit · Full page Pass the constant arguments of Dict and Object functions without
|
…json)
Why:
A prototype for deprecating `@as(json)` on external arguments. The seven
stdlib uses become an external that takes the constant plus an `@inline`
function of the same name that passes `{}` or `null`, the way
`Array.reduce` reorders its arguments. Calls compile to the same
JavaScript as before.
JS unchanged (call sites):
Example:
let merged = target->Dict.concat(dict{"b": 3})
let bare = Object.createWithNull()
Before (js):
let merged = Object.assign({}, target, {
b: 3
});
let bare = Object.create(null);
After (js):
let merged = Object.assign({}, target, {
b: 3
});
let bare = Object.create(null);
Review: What changes for users? `Stdlib_Dict.js` and `Stdlib_Object.js`
now export these functions, as `Stdlib_Array.js` exports `reduce`. A
function value such as `Dict.copy` passed around calls the exported
function instead of a wrapper made at the use site.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq
Signed-off-by: Christoph Knittel <ck@cca.io>
9bba089 to
4d2973c
Compare
✅ Compiler benchmarksAllocated wordsIn total: 653,169,466 → 653,223,087 (+0.01%). Generated projects: 627,295,414 → 627,295,264 (±0.00%).
(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions. InstructionsIn total: 8,966,803,168 → 8,966,803,168 (±0.00%). None of the 33 benchmarks changed by 0.1% or more. Output sizeIn total: 27,449,924 → 27,449,957 (±0.00%).
(inputs changed): this pull request changes runtime or Belt sources, so these benchmarks compile different code than on the base, and their changes don't count as regressions. Pull request 4d2973c compared with base ef50d81 in this run. |
rescript
@rescript/belt
@rescript/darwin-arm64
@rescript/linux-arm64
@rescript/linux-x64
@rescript/runtime
@rescript/win32-x64
commit: |
A proof of concept:
@as(json)on external arguments isn't needed. An@inlinefunction can pass the constant instead, the wayArray.reducealready reorders its arguments:This replaces all seven uses in the stdlib:
Dict.concat,Dict.concatMany,Dict.concatAll,Dict.copy(they pass{});Object.copy(passes{});Object.createWithNull,Object.createWithNullAndProperties(they passnull).Calls compile to the same JavaScript as before;
Stdlib_DictTests.mjsdoesn't change:The only difference in output:
Stdlib_Dict.jsandStdlib_Object.jsnow export these functions, asStdlib_Array.jsexportsreduce. A use as a value, such asdicts->Array.map(Dict.copy), refers to the exported function instead of a wrapper built at that spot.Without the previous PR, literal arguments would get a variable of their own (
let dict2 = {b: 3}; Object.assign({}, target, dict2)), and a literal array passed to the variadicconcatManywould no longer be expanded.Not included: a deprecation warning for
@as(json)on external arguments. That would follow if we go this way.🤖 Generated with Claude Code
https://claude.ai/code/session_01Kbf3gHZYwA1rq7zbk3dhQq