Skip to content

Fix RTTs for RTT-less instructions#4294

Merged
tlively merged 3 commits into
WebAssembly:mainfrom
tlively:gc-data-rtts
Nov 3, 2021
Merged

Fix RTTs for RTT-less instructions#4294
tlively merged 3 commits into
WebAssembly:mainfrom
tlively:gc-data-rtts

Conversation

@tlively

@tlively tlively commented Oct 30, 2021

Copy link
Copy Markdown
Member

Allocation and cast instructions without explicit RTTs should use the canonical
RTTs for the given types. Furthermore, the RTTs for nominal types should reflect
the static type hierarchy. Previously, however, we implemented allocations and
casts without RTTs using an alternative system that only used static types
rather than RTT values. This alternative system would work fine in a world
without first-class RTTs, but it did not properly allow mixing instructions that
use RTTs and instructions that do not use RTTs as intended by the M4 GC spec.

This PR fixes the issue by using canonical RTTs where appropriate and cleans up
the relevant casting code using std::variant.


The code in this PR should be complete, but it will need tests.

@kripken kripken left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment thread src/wasm-interpreter.h Outdated
}
Literal actualRtt;
if (original.isFunction()) {
// Function references always have the canonical rTTs of the functions

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Function references always have the canonical rTTs of the functions
// Function references always have the canonical RTTs of the functions

Comment thread src/wasm-interpreter.h Outdated
Comment on lines +1502 to +1505
} else if (cast.getSuccess()) {
return Literal(int32_t(1));
} else {
return Literal(int32_t(0));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else if (cast.getSuccess()) {
return Literal(int32_t(1));
} else {
return Literal(int32_t(0));
} else {
return Literal(int32_t(cast.getSuccess() ? 1 : 0));
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will use the similar bool(getSuccess()).

@tlively tlively marked this pull request as ready for review November 2, 2021 23:37
@tlively

tlively commented Nov 2, 2021

Copy link
Copy Markdown
Member Author

@tlively tlively changed the title [WIP] Fix RTTs for RTT-less instructions Fix RTTs for RTT-less instructions Nov 3, 2021
@tlively tlively requested a review from kripken November 3, 2021 00:55
@kripken

kripken commented Nov 3, 2021

Copy link
Copy Markdown
Member

Code looks good!

For the tests, should I review a diff of them after the other PR lands?

@kripken

kripken commented Nov 3, 2021

Copy link
Copy Markdown
Member

Oops, I see you wrote that in a comment...

Comment thread test/lit/exec/rtts.wast Outdated
)
)

(func $make-struct-canon (result (ref $struct))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes a sub-struct - perhaps the name should reflect that?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, made that change when I moved this test to #4301.

Comment thread test/lit/exec/rtts.wast
(call $log
(ref.test_static $sub-struct
(call $make-struct-canon)
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(renaming that function would make it more obvious why this cast works)

Allocation and cast instructions without explicit RTTs should use the canonical
RTTs for the given types. Furthermore, the RTTs for nominal types should reflect
the static type hierarchy. Previously, however, we implemented allocations and
casts without RTTs using an alternative system that only used static types
rather than RTT values. This alternative system would work fine in a world
without first-class RTTs, but it did not properly allow mixing instructions that
use RTTs and instructions that do not use RTTs as intended by the M4 GC spec.

This PR fixes the issue by using canonical RTTs where appropriate and cleans up
the relevant casting code using std::variant.
@tlively tlively enabled auto-merge (squash) November 3, 2021 20:17
@tlively tlively merged commit ab66e9a into WebAssembly:main Nov 3, 2021
@tlively tlively deleted the gc-data-rtts branch November 3, 2021 21:45
@kripken kripken mentioned this pull request Nov 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants