Partial application moves its arguments into the generated closure
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 停滞
- 技术栈
- javascript
- 领域
- compilers
调研方向
Start in compiler/ml/translcore.ml at transl_apply's uncurried_partial_application branch, then compare its argument handling with build_apply's protect path. Check the compiler tests for partial application, including cases with await, side effects, and yield. Done means arguments are evaluated once at the partial application site and remain valid outside the generated closure.
由索引模型根据 Issue 内容生成。
描述
Partial application with ... puts the supplied arguments inside the closure it creates, instead of evaluating them first.
let add = (a, b, c) => a + b + c
let f = async p => {
let h = add(await p, ...)
h(1, 2) + h(3, 4)
}
compiles to
async function f(p) {
let h = (extra, extra$1) => add(await p, extra, extra$1);
return h(1, 2) + h(3, 4) | 0;
}
await inside a non-async arrow is a JavaScript syntax error, so the module fails to load.
The same placement also re-evaluates the argument on every call:
let g = () => {
let h = add(next(), ...)
h(1, 2) + h(1, 2)
}
function g() {
let h = (extra, extra$1) => add(next(), extra, extra$1);
return h(1, 2) + h(1, 2) | 0;
}
Here next() runs twice, once for each call of h.
When h is used only once, the optimizer inlines it and both problems disappear, which may be why this hasn't been noticed.
Expected: the arguments are evaluated once, where the partial application happens:
let arg = await p;
let h = (extra, extra$1) => add(arg, extra, extra$1);
Cause: in compiler/ml/translcore.ml, transl_apply's uncurried_partial_application branch puts the translated arguments directly into the body of the new function. The optional-argument path (build_apply) already let-binds non-trivial arguments outside the closure (protect); the ... path should do the same.
This also blocks generator functions, since a yield would be moved into the closure the same way.
Reproduced on master (8556f0ad72).
- 主要语言
- ReScript
- 星标
- 7.5k
- 派生
- 483
- 平均合并
- 1 天 2 小时
- 30 天内合并 PR
- 164
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rescript-lang/rescript 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 48/100
rescript-lang/rescript#8938 ·
维护者通常 1 天内回复
-
discussion enhancement
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8934 · 1 个 reaction ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
rescript-lang/rescript#8910 ·
维护者通常 1 天内回复
-
Nested JSX components under React Server Components: derive flat exports from the signature可能已有人在做 @cknitt 于 3 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 25/100
rescript-lang/rescript#8901 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
rescript-lang/rescript#8897 ·
维护者通常 1 天内回复
查看 rescript-lang/rescript 的全部 Issue
相似的 Issue
-
bug priority: P2
难度 1/5 1 小时以内 新手友好度 78/100
维护者通常 1 天内回复
-
confirmed generated by fuzzer llvm:optimizations miscompilation
难度 2/5 1-3 小时 新手友好度 78/100
llvm/llvm-project#234325 ·
维护者通常 1 天内回复
-
grammar selfhost sev-3
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 78/100
gren-lang/compiler-common#41 ·