This repository has been archived by the owner on Jul 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Separate IDs of Wasm things from their names. #134
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sjrd
force-pushed
the
separate-ids-from-names
branch
from
May 18, 2024 15:46
fdf764c
to
97d73e3
Compare
tanishiking
approved these changes
May 21, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you very much for this huge work 💯
* generated by `LibraryPatches.deriveBoxClass`, instead of explicitly | ||
* calling the constructor. We can do this because we know that this is | ||
/* We use a direct `StructNew` instead of the logical call to `newDefault` | ||
* plus constructor call. We can do this because we know that this is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Comment on lines
+46
to
+52
private val fieldIdxValues: Map[TypeID, Map[FieldID, Int]] = { | ||
(for { | ||
recType <- module.types | ||
SubType(typeID, _, _, _, StructType(fields)) <- recType.subTypes | ||
} yield { | ||
typeID -> fields.map(_.id).zipWithIndex.toMap | ||
}).toMap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, I like having name resolution for field access only in the binary writer (instead of getFieldIdx
everywhere) looks much readable!
Since we are directly setting the field anyway, we can go further and use `struct.new` without any function call.
sjrd
force-pushed
the
separate-ids-from-names
branch
from
May 21, 2024 06:40
97d73e3
to
164b2cc
Compare
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.
sjrd
force-pushed
the
separate-ids-from-names
branch
from
May 21, 2024 07:11
164b2cc
to
6344348
Compare
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 areOriginalName
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
andhashCode
. This allows to define them as case classes that directly embedClassName
s andMethodName
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 theClassInfo
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.