Repository navigation
Conversation
tlively
left a comment
There was a problem hiding this comment.
Gemini noticed that this exposes a bug with call.without.effects:
(module
(type $sig (func))
(import "binaryen-intrinsics" "call.without.effects" (func $cwe (param funcref)))
(func $test (param $f funcref)
(call $cwe (ref.cast (ref $sig) (local.get $f)))
)
)
| return; | ||
| } | ||
| auto& glb = exprGLBs[curr]; | ||
| auto newType = glb.noted() ? glb.getGLB() : getTop(curr->type); |
There was a problem hiding this comment.
I see that we have this pattern above where we update local types as well, but it would be nice to clean this up. I believe we could do that by using exprGLBs.find(curr) instead of exprGLBs[curr] just above this to avoid inserting new default-initialized GLBs. All the GLBs already in the map should already have been noted.
(And if we wanted to, we could clean this pattern up for the localGLBs by initializing them with their top types.)
There was a problem hiding this comment.
This is shorter code than using find, though? Another benefit of the current code is that it looks the same in the other case too, even though one is a vector and one is a map - makes the overall pass easier to read I think?
There was a problem hiding this comment.
Here's another alternative. It just seems a shame to have a nice utility like GLBFinder and then not take advantage of its simple interface just because we didn't initialize it.
| auto newType = glb.noted() ? glb.getGLB() : getTop(curr->type); | |
| glb.note(getTop(curr->type); | |
| auto newType = glb.noted(); |
I don't feel too strongly about this, though. I agree short and consistent code is a good goal.
There was a problem hiding this comment.
This reads oddly to me (note, then check if noted). How about glb.getNotedGLBOr(otherwise) which returns the GLB if noted, otherwise a given value?
There was a problem hiding this comment.
We could add a test with nested exact casts, where generalizability propagates from outer to inner casts. Something like this:
(func (result anyref)
(local $x (exact $foo))
(ref.cast (ref (exact $foo))
(ref.cast (ref (exact $foo))
(local.get $x)
)
)
)
There was a problem hiding this comment.
Does func $chained in test/lit/passes/type-generalizing-tnh.wast not do this?
;; TNH: (func $chained (type $6) (param $any anyref) (result (ref $Mid))
;; TNH-NEXT: (ref.cast (ref $Mid)
;; TNH-NEXT: (ref.cast anyref
;; TNH-NEXT: (local.get $any)
;; TNH-NEXT: )
;; TNH-NEXT: )
;; TNH-NEXT: )
;; NO_TNH: (func $chained (type $7) (param $any anyref) (result (ref $Mid))
;; NO_TNH-NEXT: (ref.cast (ref $Bot)
;; NO_TNH-NEXT: (ref.cast (ref $Mid)
;; NO_TNH-NEXT: (local.get $any)
;; NO_TNH-NEXT: )
;; NO_TNH-NEXT: )
;; NO_TNH-NEXT: )
(func $chained (param $any anyref) (result (ref $Mid))
;; Inner cast weakens to anyref; outer cast weakens to (ref $Mid).
(ref.cast (ref $Bot)
(ref.cast (ref $Mid)
(local.get $any)
)
)
)There was a problem hiding this comment.
Almost, but that doesn't test the special treatment of exact casts over several steps.
There was a problem hiding this comment.
Ok, added a test with a chain of exact casts.
|
|
This form of cast is very easy to generalize: it can become as general as
where its output goes to.