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

Relax typing of classification instructions; opcode for dataref #184

Merged
merged 3 commits into from
Jan 21, 2021

Conversation

rossberg
Copy link
Member

Addresses #180 and #183.

@rossberg
Copy link
Member Author

@manoskouk, PTAL.

Copy link
Contributor

@manoskouk manoskouk left a comment

Choose a reason for hiding this comment

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

LGTM with one comment.

@@ -325,39 +325,44 @@ Tentatively, support a type of guaranteed unboxed scalars.
- `ref.is_i31 : [anyref] -> [i32]`

* `br_on_func <labelidx>` branches if a reference is a function
- `br_on_func $l : [anyref] -> [anyref]`
- iff `$l : [funcref]`
- `br_on_func $l : [(ref null ht)] -> [(ref null ht)]`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the typing of all br_on_* instructions, including br_on_cast, could be further refined to preserve their argument's nullability, similarly to ref.cast.

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, PTAL!

Copy link
Contributor

@manoskouk manoskouk left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! We may want the same change for br_on_cast.

@rossberg
Copy link
Member Author

Ah, yes. I included that change, and simplified their typing rules. While at it, I also removed the explicit type index on those instructions, which is no longer consistent with the rest of the language. PTYAL.

@rossberg rossberg merged commit ed9d435 into master Jan 21, 2021
- and `(type $t) <: ht`
* `ref.test` tests whether a reference value's [runtime type](#values) is a [runtime subtype](#runtime) of a given RTT
- `ref.test : [t' (rtt n? $t)] -> [i32]`
- iff `t' <: dataref` or `t' <: funcref`
Copy link
Contributor

Choose a reason for hiding this comment

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

I am just noticing: Don't we want to be able to cast references directly to concrete types without casting them to dataref or funcref first? If so, this should be ref.test : [anyref (rtt n? $t)] -> [i32], and similarly for ref.cast. In any case, t' <: (ref null data), or we need to make dataref == (ref null data).

Copy link
Member Author

@rossberg rossberg Jan 21, 2021

Choose a reason for hiding this comment

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

Ah, no, the purpose of introducing the separate classification instructions actually was to simplify the test/cast instructions, so that they only operate on references that are known to have an RTT. Otherwise their function would overlap with the classification instructions. See #150 for more context.

You are right about the null thing, fixed.

- `br_on_cast $l : [t (rtt n? $t')] -> [t]`
- iff `$l : [t']`
- and `t <: dataref` or `t <: funcref`
- and `(ref $t) <: t'`
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there are some aliased variables here. It should be:
br_on_cast $l : [t1 (rtt n? $t2)] -> [t1]

  • iff $l : [t3]
  • and t1 <: (ref null data) or t1 <: funcref (instead, t1 <: anyref if we go with the above suggestion)
  • and (ref $t2) <: t3

Copy link
Member Author

Choose a reason for hiding this comment

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

There was a typo in the last line, which should have been (ref $t') (fixed). But I think the others are correct, considering that $t' and t' are different names and in different categories.

Copy link
Member Author

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Thanks, I pushed a quick fix to the typos you point out.

- and `(type $t) <: ht`
* `ref.test` tests whether a reference value's [runtime type](#values) is a [runtime subtype](#runtime) of a given RTT
- `ref.test : [t' (rtt n? $t)] -> [i32]`
- iff `t' <: dataref` or `t' <: funcref`
Copy link
Member Author

@rossberg rossberg Jan 21, 2021

Choose a reason for hiding this comment

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

Ah, no, the purpose of introducing the separate classification instructions actually was to simplify the test/cast instructions, so that they only operate on references that are known to have an RTT. Otherwise their function would overlap with the classification instructions. See #150 for more context.

You are right about the null thing, fixed.

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.

2 participants