8000 Wasm: Use builtin string constants from JS string builtins. · sjrd/scala-js@64edcce · GitHub
[go: up one dir, main page]

Skip to content

Commit 64edcce

Browse files
committed
Wasm: Use builtin string constants from JS string builtins.
In addition to builtin functions, the JS string builtins proposal provides a way to import (valid UTF-8) string literals from a dedicated module. Instead of using a custom data segment, we now import all the strings we can from that builtin module. For the rare cases where we need a string literal that is not a valid UTF-16 string (and therefore cannot be encoded into valid UTF-8), we use custom imports that we fill in from the JS side. This alternate encoding is a lot more economical in terms of code size. It shaves off 5% of the fastLink output, and 8.5% of the fullLink output. Moreover, it means our string literals are constant expression globals, which we can directly use in the initialization of `typeData` constant structs.
1 parent 70a4164 commit 64edcce

File tree

12 files changed

+237
-346
lines changed

12 files changed

+237
-346
lines changed

linker/shared/src/main/scala/org/scalajs/linker/backend/wasmemitter/ClassEmitter.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ class ClassEmitter(coreSpec: CoreSpec) {
212212
coreSpec.semantics.runtimeClassNameMapper,
213213
className.nameString
214214
)
215-
val nameDataValue: List[wa.Instr] =
216-
ctx.stringPool.getConstantStringDataInstr(nameStr)
215+
val nameValue = ctx.stringPool.getConstantStringInstr(nameStr)
217216

218217
val kind = className match {
219218
case ObjectClass => KindObject
@@ -299,8 +298,10 @@ class ClassEmitter(coreSpec: CoreSpec) {
299298
elemsInstrs :+ wa.ArrayNewFixed(genTypeID.reflectiveProxies, reflectiveProxies.size)
300299
}
301300

302-
nameDataValue :::
301+
(
303302
List(
303+
// name
304+
nameValue,
304305
// kind
305306
wa.I32Const(kind),
306307
// specialInstanceTypes
@@ -312,8 +313,6 @@ class ClassEmitter(coreSpec: CoreSpec) {
312313
List(
313314
// componentType - always `null` since this method is not used for array types
314315
wa.RefNull(watpe.HeapType(genTypeID.typeData)),
315-
// name - initially `null`; filled in by the `typeDataName` helper
316-
wa.RefNull(watpe.HeapType.NoExtern),
317316
// the classOf instance - initially `null`; filled in by the `createClassOf` helper
318317
wa.RefNull(watpe.HeapType(genTypeID.ClassStruct)),
319318
// arrayOf, the typeData of an array of this type - initially `null`; filled in by the `arrayTypeData` helper
@@ -327,6 +326,7 @@ class ClassEmitter(coreSpec: CoreSpec) {
327326
// Generated instructions create an array of reflective proxy structs, where each struct
328327
// contains the ID of the reflective proxy and a reference to the actual method implementation.
329328
reflectiveProxiesInstrs
329+
)
330330
}
331331

332332
private def genTypeDataGlobal(className: ClassName, typeDataTypeID: wanme.TypeID,
@@ -1366,7 +1366,7 @@ class ClassEmitter(coreSpec: CoreSpec) {
13661366

13671367
ctx.moduleBuilder.addImport(
13681368
wamod.Import(
1369-
"__scalaJSExportSetters",
1369+
ExportSettersModule,
13701370
exportedName,
13711371
wamod.ImportDesc.Func(
13721372
functionID,

0 commit comments

Comments
 (0)
0