swiftwasm / swiftwasm/JavaScriptKit
Support exporting structs as a reference
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Swift
- Estrelas
- 986
- Forks
- 76
- Merge médio
- 21h 11min
- PRs com merge (30d)
- 4
Descrição
The current mechanism for exporting structs works great for simple structs, like @JS struct Point { let x: Double; let y: Double }. When passed out or into Swift, all the members of the struct are copied.
However, it is also common in Swift to have a less trivial struct, for example:
@JS struct Polygon {
var vertices: [Point]
}
A complex polygon could have tens of thousands of vertices. This works fine in Swift, since the Array is COW. However, this is less than ideal when interoperating with JavaScript, where all the vertices would have to be copied every time the struct crosses the boundary.
Mutating functions currently don’t work on structs, but if they were working, this would also require copying the whole contents of the struct after each call. For example, a mutating addVertex function on Polygon would require copying every vertex across the boundary.
To workaround this issue, you could convert the struct into a class. This improves interoperability with JavaScript, however it can make Swift code less idiomatic.
Proposed Solution
A solution would be allowing structs to be exported using a heap allocated box, which could be expressed using @JS(boxed: true). A “boxed” struct would lead to very similar generated code to a class, where JavaScript just has a Swift-owned pointer.
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.
Direção de pesquisa
Comece rastreando o mecanismo atual de exportação de structs e o código gerado usado quando structs atravessam a fronteira Swift–JavaScript. Compare esse comportamento com a forma proposta @JS(boxed: true) e a issue #736 e, em seguida, verifique se boxed structs preservam o comportamento baseado em ponteiros pretendido sem copiar seu conteúdo.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- javascript, swift
- Domínio
- api, web-dev
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Pouca atividade
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 45/100