Partial application moves its arguments into the generated closure
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Bug
- Clareza
- Claramente especificada
- Status de atividade
- Estagnada
- Stack de tecnologia
- javascript
- Domínio
- compilers
Direção de pesquisa
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.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
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).
- Linguagem predominante
- OCaml
- Estrelas
- 7.5k
- Forks
- 483
- Merge médio
- 21h 8min
- PRs com merge (30d)
- 183
Preparar o ambiente
Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de rescript-lang/rescript
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
rescript-lang/rescript#8996 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 70/100
rescript-lang/rescript#8997 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 1-2 dias Facilidade para iniciantes 55/100
rescript-lang/rescript#8995 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 68/100
rescript-lang/rescript#8994 ·
Mantenedores costumam responder em até 1 dia
-
Issues from differential semantic drift analysis (a7721303 to b123b7c3)Talvez já em andamento @cknitt assumiu hoje. Aberta
rescript-lang/rescript#8980 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
Todas as issues de rescript-lang/rescript
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 83/100
Mantenedores costumam responder em até 1 dia
-
bug P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
Mantenedores costumam responder em até 1 dia
-
duplicate
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
numba/numba#10939 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Quantinuum/tket#2255 ·
Mantenedores costumam responder em até 1 dia
-
REPL and --show-tokens abort with "Token conversion not implemented yet" on .xor., byte and in outAbertabug low priority tokenizer
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
Mantenedores costumam responder em até 1 dia