-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit 5f1d5cf
Scala.js: Remove spurious
When B <: A and C <: A, `linkTimeIf[A](cond) { B }{ C }` would
generate an `.asInstanceOf[A]` that casts the resulting value to a
supertype. However, this cast is redundant, as the linker will
prune one branch at link time, and the remaining expression is
already known to be a compatible type.
This commit eliminates the surrounding `.asInstanceOf` around the
`linkTimeIf[T]` when both `thenp` and `elsep` are known to be
subtypes of `T`. The optimizer already routinely performs this
optimization. However, that comes too late for the module instance
field alias analysis performed by `IncOptimizer`. In that case,
while the desugarer removes the `LinkTimeIf`, the extra
`AsInstanceOf` prevents aliasing the field. Removing the cast ahead
of time in the compiler allows field aliases to be recognized in
the presence of `LinkTimeIf`s.
This commit is a forward port of the Scala.js commit
scala-js/scala-js@9bb267c js.AsInstanceOf
around js.LinkTimeIf
.1 parent 33aa948 commit 5f1d5cf
1 file changed
+23
-1
lines changedOriginal file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
3321 | 3321 |
| |
3322 | 3322 |
| |
3323 | 3323 |
| |
3324 | - | ||
3324 | + | ||
3325 | + | ||
3326 | + | ||
3327 | + | ||
3328 | + | ||
3329 | + | ||
3330 | + | ||
3331 | + | ||
3332 | + | ||
3333 | + | ||
3334 | + | ||
3335 | + | ||
3336 | + | ||
3337 | + | ||
3338 | + | ||
3339 | + | ||
3340 | + | ||
3341 | + | ||
3342 | + | ||
3343 | + | ||
3344 | + | ||
3345 | + | ||
3346 | + | ||
3325 | 3347 |
| |
3326 | 3348 |
| |
3327 | 3349 |
| |
|
0 commit comments