Skip to content
This repository was archived by the owner on Apr 25, 2025. It is now read-only.

Relax nullability for br_on_cast #343

Merged
merged 3 commits into from
Dec 9, 2022
Merged

Relax nullability for br_on_cast #343

merged 3 commits into from
Dec 9, 2022

Conversation

rossberg
Copy link
Member

@rossberg rossberg commented Dec 9, 2022

Address #342 and simplify rules on the way. Also adjust interpreter and add tests.

@Liedtke, PTAL.

- if `null?` is present, returns 1 for null, otherwise 0
- `ref.test rt : [(ref rt')] -> [i32]`
- iff `rt <: trt` and `rt' <: trt` for some `trt`
- if `rt` contains `null`, returns 1 for null, otherwise 0
Copy link
Member

Choose a reason for hiding this comment

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

What does "rt contains null" mean? Is rt a reference type? Then it would be different in kind from rt'.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, I was using the wrong factorisation. Fixed.

Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

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

Great, this makes sense and is even simpler than before.

@rossberg rossberg merged commit 91a5b69 into main Dec 9, 2022
@rossberg rossberg deleted the br_on_Cast.null branch December 9, 2022 16:19
- if `null?` is present, a null operand is passed through, otherwise traps on null
- equivalent to `(block $l (param anyref) (result (ref null? ht)) (br_on_cast null? ht $l) (unreachable))`
- if `rt` contains `null`, a null operand is passed through, otherwise traps on null
- equivalent to `(block $l (param anyref) (result rt) (br_on_cast $l rt) (unreachable))`
Copy link

Choose a reason for hiding this comment

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

I think, this isn't true in all cases. For externref types or funcref types anyref would not be compatible.
is there a way to make it look nice while also applying to funcref types? Otherwise we could add a (for input values of the anyref type hierarchy) or a similar restriction to this line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, indeed, this ceased to hold when we split the type hierarchy.

Copy link
Member Author

Choose a reason for hiding this comment

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

I pushed a quick fix that simply replaces anyref with trt, as occurring in the typing rule.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants