Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Separate IDs of Wasm things from their names.
Browse files Browse the repository at this point in the history
Previously, we eagerly generated string names for every Wasm thing,
and used that name both as their identity and as their debug name.

Now, we clearly separate those concepts: identities are instances
of abstract traits such as `FunctionID`, while debug names are
`OriginalName`s. Original names are only stored at the definition
site, while IDs are used to link definition and use sites.

IDs only need to have meaningful `equals` and `hashCode`. This
allows to define them as case classes that directly embed
`ClassName`s and `MethodName`s (among others), without having to
decode them or serialize them.

Moreover, since `OriginalName`s are internally represented as UTF-8
strings, we also avoid the cost of decoding and reencoding them
when writing binary `.wasm` files. The text writer gets more work
to do, but it is not on the performance-sensitive path, so this is
not really an issue.

For struct field IDs, this change also implies merging field *names*
and field *indices*. Since references to fields can now use
`FieldID`s as well, it removes a bit of bookkeeping at the
`ClassInfo` level. Both instance field indices and method table
entry indices are late-bound in the binary emitter. We do not have
to eagerly compute them.
  • Loading branch information
sjrd committed May 18, 2024
1 parent 22919ed commit fdf764c
Show file tree
Hide file tree
Showing 20 changed files with 1,809 additions and 1,482 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class WebAssemblyLinkerBackend(

def maybeWriteWatFile(): Future[Unit] = {
if (linkerConfig.prettyPrint) {
val textOutput = new TextWriter().write(wasmModule)
val textOutput = new TextWriter(wasmModule).write()
val textOutputBytes = textOutput.getBytes(StandardCharsets.UTF_8)
outputImpl.writeFull(watFileName, ByteBuffer.wrap(textOutputBytes))
} else {
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit fdf764c

Please sign in to comment.