Skip to content

i14623.scala fails on Scala.js as of 3.1.3 #15494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
armanbilge opened this issue Jun 21, 2022 · 3 comments · Fixed by #15498
Closed

i14623.scala fails on Scala.js as of 3.1.3 #15494

armanbilge opened this issue Jun 21, 2022 · 3 comments · Fixed by #15498
Assignees
Labels
area:scala.js area:transform itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@armanbilge
Copy link
Contributor

Compiler version

3.1.3

Minimized code

https://github.com/lampepfl/dotty/blob/75d8eea1e943bbd2c605d8411c2d52d69974d6f3/tests/run/i14623.scala#L1-L15

Output

$ scala-cli -S 3.1.3 --js i14623.scala 
/tmp/main6684577165524698363.js:838
      throw e
      ^

<ref *1> $c_jl_AssertionError [java.lang.AssertionError]: assertion failed
    at $c_sr_Scala3RunTime$.assertFailed__E (/tmp/main6684577165524698363.js:1539:9)
    at $c_Li14623$package$.Test__V (/tmp/main6684577165524698363.js:899:28)
    at $s_LTest__main__AT__V (/tmp/main6684577165524698363.js:832:27)
    at Object.<anonymous> (/tmp/main6684577165524698363.js:2283:1)
    at Object.<anonymous> (/tmp/main6684577165524698363.js:2284:4)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12) {
  jl_Throwable__f_s: 'assertion failed',
  jl_Throwable__f_e: null,
  jl_Throwable__f_enableSuppression: true,
  jl_Throwable__f_writableStackTrace: true,
  jl_Throwable__f_stackTraceStateInternal: [Circular *1],
  jl_Throwable__f_stackTrace: null,
  jl_Throwable__f_suppressed: null
}

Expectation

It works in 3.1.2:

$ scala-cli -S 3.1.2 --js i14623.scala
# (no output)

And in JVM for 3.1.3:

$ scala-cli -S 3.1.3 i14623.scala
# (no output)
@armanbilge armanbilge added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 21, 2022
@griggt griggt added area:scala.js area:transform regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 22, 2022
@griggt
Copy link
Contributor

griggt commented Jun 22, 2022

First bad commit is 81cbe32 from #14295

@armanbilge
Copy link
Contributor Author

Thanks for tracking that down!

@sjrd sjrd self-assigned this Jun 22, 2022
@sjrd
Copy link
Member

sjrd commented Jun 22, 2022

I started digging into this. It happens because EtaReduce does not work for non-specialized functions. And Scala.js disables function specialization altogether.

I can reproduce the issue on Scala/JVM if I disable the SpecializeFunctions phase. I also suspect that EtaReduce would fail even in regular Scala/JVM for Function3+ as well as for Function2 with non-specializable param types. But the test here is about by-names, so they are Function0s by construction.

sjrd added a commit to dotty-staging/dotty that referenced this issue Jun 22, 2022
In Scala.js, function specialization is disabled. This means that
non-specialized functions can reach `EtaReduce`. Previously, it
did not handle the shape of right-hand-side for non-specialized
functions returning primitives. We fix the issue by handling those,
like we already handled `.asInstanceOf`s.
@Kordyjan Kordyjan linked a pull request Jun 22, 2022 that will close this issue
odersky added a commit that referenced this issue Jun 22, 2022
…ed-funs

Fix #15494: Handle non-specialized functions in EtaReduce.
Kordyjan pushed a commit to dotty-staging/dotty that referenced this issue Jun 22, 2022
In Scala.js, function specialization is disabled. This means that
non-specialized functions can reach `EtaReduce`. Previously, it
did not handle the shape of right-hand-side for non-specialized
functions returning primitives. We fix the issue by handling those,
like we already handled `.asInstanceOf`s.
sjrd added a commit that referenced this issue Jun 22, 2022
Backport #15498: Fix #15494: Handle non-specialized functions in EtaReduce.
@sjrd sjrd added this to the 3.2.0 backports milestone Jul 23, 2022
bishabosha pushed a commit to dotty-staging/dotty that referenced this issue Oct 18, 2022
In Scala.js, function specialization is disabled. This means that
non-specialized functions can reach `EtaReduce`. Previously, it
did not handle the shape of right-hand-side for non-specialized
functions returning primitives. We fix the issue by handling those,
like we already handled `.asInstanceOf`s.
@Kordyjan Kordyjan modified the milestones: 3.2.0 backports, 3.2.1 Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:scala.js area:transform itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants