Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Partial application moves its arguments into the generated closure

未关闭
#8,932 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@cknitt 已经在做这个了。

开始于 2026年10月20日。

  • #8936 来自 @cknitt —— 未关闭

评估

难度
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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rescript-lang/rescript 的其他 Issue

查看 rescript-lang/rescript 的全部 Issue

相似的 Issue

更多 Compilers Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。