Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Partial application moves its arguments into the generated closure

Chiusa
#8,932 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@cknitt ci sta già lavorando.

Dal 20/10/2026.

  • #8936 di @cknitt — aperta

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
javascript
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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).

Lingua principale
OCaml
Stelle
7.5k
Fork
483
Merge medio
1g 1h
PR unite (30g)
169

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rescript-lang/rescript

Tutte le issue di rescript-lang/rescript

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.