Skip to content
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

Infinite compile time when exceeded amount of parameters of class #20134

Closed
Nojipiz opened this issue Apr 8, 2024 · 9 comments · Fixed by #20817
Closed

Infinite compile time when exceeded amount of parameters of class #20134

Nojipiz opened this issue Apr 8, 2024 · 9 comments · Fixed by #20817
Assignees
Labels
area:infer itype:bug itype:compiler hangs Issues where the compiler hangs. regression This worked in a previous version but doesn't anymore stat:fixed in next The issue was fixed in Next and only still applies to LTS.

Comments

@Nojipiz
Copy link

Nojipiz commented Apr 8, 2024

Compiler version

Scala: 3.3.3

Minimized code

  trait ExampleTrait1
  trait ExampleTrait2
  class ExampleClass(traitOne: ExampleTrait1, traitTwo: ExampleTrait2)

  def fun[In](a: In): Unit = println(0)

  fun(new ExampleClass(_, _, _))

Output

java.lang.OutOfMemoryError: Java heap space

Expectation

An error at compile time because the exceeded parameter of "ExampleClass", it just tries to compile until the java heap space is over.

@Gedochao
Copy link
Contributor

Fails at compile time in Next (3.4.1)

-- [E081] Type Error: /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/.scala-build/compiler-repro_b7340921ea-40b92162c2/src_generated/main/smth.scala:13:27 
13 |fun(new ExampleClass(_, _, _))
   |                           ^
   |        Missing parameter type
   |
   |        I could not infer the type of the parameter _$3
   |        in expanded function:
   |          (_$1, _$2, _$3) => new smth$_.this.ExampleClass(_$1, _$2, _$3)
   |        Expected type for the whole anonymous function:
   |          In
   |
   |        where:    In is a type variable
1 error found
Compilation failed

The compilation indeed hangs in LTS.

@Gedochao Gedochao added itype:compiler hangs Issues where the compiler hangs. stat:fixed in next The issue was fixed in Next and only still applies to LTS. area:typer area:infer 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 area:typer labels Apr 10, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Apr 10, 2024

So this unfortunately looks like a regression on the LTS.

The last LTS to fail correctly in compile time: 3.3.1

-- [E081] Type Error: /Users/pchabelski/IdeaProjects/scala-cli-tests/compiler-repro/.scala-build/compiler-repro_a69ec373e9-40b92162c2/src_generated/main/smth.scala:13:27 
13 |fun(new ExampleClass(_, _, _))
   |                           ^
   |   Missing parameter type
   |
   |   I could not infer the type of the parameter _$3 of expanded function:
   |   (_$1, _$2, _$3) => new smth$_.this.ExampleClass(_$1, _$2, _$3).
1 error found
Compilation failed

The first LTS to hang on infinite compilation: 3.3.2
Last good nightly (raising the error): 3.3.2-RC1-bin-20230717-2753a17-NIGHTLY
First nightly introducing the problem: 3.3.2-RC1-bin-20230718-da16f43-NIGHTLY

The compilation still hangs on Next 3.4.0
First Next nightly to fix it (have the error again, rather than hang): 3.4.1-RC1-bin-20240122-ca18f4a-NIGHTLY
First good Next is 3.4.1

@noti0na1
Copy link
Member

I couldn't reproduce the infinite hang in LTS (3.3.3), 3.4, or nightly

> scala-cli compile -S 3.lts Stest.scala
Compiling project (Scala 3.3.3, JVM (11))
[error] ./Stest.scala:234:26
[error] Could not infer type for parameter _$3 of anonymous function
[error] 
[error] In expanded function:
[error] (_$1, _$2, _$3) => new ExampleClass(_$1, _$2, _$3)
[error]   new ExampleClass(_, _, _)
[error]                          ^
Error compiling project (Scala 3.3.3, JVM (11))
Compilation failed

Although the error is different in 3.3.

@Nojipiz
Copy link
Author

Nojipiz commented May 12, 2024

@noti0na1 How did you use "3.lts" as Scala Version for scala-cli?

When i try to execute your command the output is:

[error]  Cannot find matching Scala version for '3.lts
You can only choose one of the 3.x, 2.13.x, and 2.12.x. versions.
The latest supported stable versions are 2.12.17, 2.13.10, 3.2.2.
In addition, you can request compilation with the last nightly versions of Scala,
by passing the 2.nightly, 2.12.nightly, 2.13.nightly, or 3.nightly arguments.
Specific Scala 2 or Scala 3 nightly versions are also accepted.

Even with scala-cli, you can reproduce the error using

  • Scala-CLI version 1.0.0-RC2
  • OpenJDK 19
  • Scala 3.3.3
> scala-cli compile -S 3.3.3 Stest.scala
Starting compilation server
Compiling project (Scala 3.3.3, JVM)

And it hangs until java.lang.OutOfMemoryError: Java heap space

@He-Pin
Copy link
Contributor

He-Pin commented May 12, 2024

You need scala cli 1.3.1

@Nojipiz
Copy link
Author

Nojipiz commented May 12, 2024

Thanks @He-Pin, the latest Scala-cli version that i got from my distro is 1.3.0 but it was enough to run the command.

scala-cli updated and it stills goes to "infinite compiling"

  • Scala-CLI version 1.0.0-RC2
  • OpenJDK 21
  • Scala 3.3.3 (using the 3.lts version at scala-cli)
> scala-cli compile -S 3.lts Stest.scala
Starting compilation server
Compiling project (Scala 3.3.3, JVM (21))

And it does nothing from there.

@noti0na1
Copy link
Member

I was able to reproduce on my another system, with smaller memory.

@noti0na1
Copy link
Member

The nightly versions I found may related to this issue:

  • 3.4.0-RC1-bin-20240105-d2cc3ae-NIGHTLY
  • 3.4.0-RC1-bin-20240106-c15cc9c-NIGHTLY

@WojciechMazur
Copy link
Contributor

The bisect for a fix seems to point to 708e640, cherry-pick to the current LTS seems to fix the issue

@WojciechMazur WojciechMazur linked a pull request Jun 27, 2024 that will close this issue
WojciechMazur added a commit that referenced this issue Jun 28, 2024
Backports #19338 to the LTS branch.
Fixes #20134

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:infer itype:bug itype:compiler hangs Issues where the compiler hangs. regression This worked in a previous version but doesn't anymore stat:fixed in next The issue was fixed in Next and only still applies to LTS.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants