Stdlib soundness of option returning functions
Mantenedores costumam responder em até 1 dia
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 25/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Ativa
- Stack de tecnologia
- ocaml
- Domínio
- backend-api-design
Direção de pesquisa
Start by examining the standard library bindings for Array.shift, Array.pop, Array.get, and Map.get, then trace how option-returning functions are represented and compiled. The issue proposes several competing approaches, so first determine which behavior maintainers want; done means the selected approach makes these functions sound while addressing the interop edge cases raised.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
Array.shift, Array.pop, Array.get, Map.get, and likely others are unsound, see Playground.
Here is what a correct version of shift could be:
let shiftSafe = xs =>
if xs->Array.isEmpty {
None
} else {
let value = xs->Array.getUnsafe(0)
let _ = xs->Array.shift
Some(value)
}
This is a common mistake when writing JS bindings and can be unexpected to users who expect ReScript to be a safe language.
I couldn't find a previous discussion, but I believe this needs a bit of consideration. The choices I see are:
- Implement safe ReScript version of
Stdlibfunctions, rename the zero overhead toshiftUnsafe,getUnsafe, etc. - Fix the compiler's handling of option-returning functions.
- Fix the representation of options.
Unfortunately, I think there will always be edge-cases that make (2) a losing battle. Even with correct code generation, people often use imprecise types for interop making compile-time information insufficient to prevent unexpected results. For example, users storing undefined containing data in a JSON type.
Similar to the previous reasoning, (3) is likely going to cause too many issues from users that are relying on a particular option implementation.
So I believe (1) is the correct choice for the standard library. However, this still makes the "obvious" implementation of JS bindings written by users prone to errors. One idea would be to generate a fixture by default unless disabled:
@send external shift: array<'a> => option<'a> = "shift"
@send @noInterop external shiftUnsafe: array<'a> => option<'a> = "shift"
// Stdlib_Array.bs.js
let shift = t => Primitive_option.some(t.shift())
- Linguagem predominante
- OCaml
- Estrelas
- 7.5k
- Forks
- 485
- Merge médio
- 17h 9min
- PRs com merge (30d)
- 264
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
-
Exception analysis does not know the Temporal `fromStringOrThrow` functionsTalvez já em andamento @cknitt assumiu há 2 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
rescript-lang/rescript#9182 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 55/100
rescript-lang/rescript#9230 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 3/5 1-2 dias Facilidade para iniciantes 72/100
rescript-lang/rescript#9229 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 44/100
rescript-lang/rescript#9228 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
rescript-lang/rescript#9227 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de rescript-lang/rescript
Issues semelhantes
-
t/bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 75/100
dotnet/maui#39950 · 1 reação ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
processing/p5.sound.js#132 ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 73/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
drizzle-team/drizzle-orm#6639 ·
Mantenedores costumam responder em até 4 dias