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

Stack overflow in compiler on a cyclic import #760

Open
jiribenes opened this issue Jan 7, 2025 · 2 comments
Open

Stack overflow in compiler on a cyclic import #760

jiribenes opened this issue Jan 7, 2025 · 2 comments
Labels
bug Something isn't working errormessage

Comments

@jiribenes
Copy link
Contributor

jiribenes commented Jan 7, 2025

Cyclic imports make the compiler crash. It would be appropriate to detect cyclic imports and report them to the user in a nicer way :)
I consider this pretty low priority since it's somewhat obvious what the problem is from the crash.

(Reported by @TheDying0fLight)

a.effekt

module a

import b

b.effekt

module b

import a

crashes the compiler:

[info] ./a.effekt:3:1: Effekt Compiler Crash: null
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Compiler.runFrontend(Compiler.scala:138)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Compiler.runFrontend$(Compiler.scala:95)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.generator.js.JavaScript.runFrontend(JavaScript.scala:12)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ModuleDB.tryModuleOf(ModuleDB.scala:53)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ModuleDB.tryModuleOf$(ModuleDB.scala:14)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.tryModuleOf(Context.scala:40)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ModuleDB.moduleOf(ModuleDB.scala:42)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ModuleDB.moduleOf$(ModuleDB.scala:14)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.moduleOf(Context.scala:40)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ModuleDB.moduleOf(ModuleDB.scala:36)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$.effekt$namer$Namer$$$_$importDependency$1(Namer.scala:49)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$$anon$1.$anonfun$2(Namer.scala:75)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.messages$ErrorReporter.at(Messages.scala:147)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.messages$ErrorReporter.at$(Messages.scala:99)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.at(Context.scala:40)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$$anon$1.applyOrElse(Namer.scala:75)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$$anon$1.applyOrElse(Namer.scala:73)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at scala.collection.immutable.List.collect(List.scala:267)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$.resolve(Namer.scala:77)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$.run$$anonfun$1(Namer.scala:38)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.using$$anonfun$1(Context.scala:81)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ContextOps.in(Context.scala:30)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.ContextOps.in$(Context.scala:19)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.effekt$namer$NamerOps$$super$in(Context.scala:40)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.NamerOps.in(Namer.scala:791)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.NamerOps.in$(Namer.scala:776)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.in(Context.scala:90)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.using(Context.scala:82)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$.run(Namer.scala:38)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.namer.Namer$.run(Namer.scala:35)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase$$anon$1.run$$anonfun$1(Phase.scala:51)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at scala.Option.flatMap(Option.scala:283)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase$$anon$1.run(Phase.scala:51)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase$task$2$.run(Phase.scala:87)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.Task$.$anonfun$1(Task.scala:139)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.context.Context.withMessages(Context.scala:105)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.Task$.compute(Task.scala:140)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.Task$.need(Task.scala:169)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.Task$.need(Task.scala:160)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.Task.apply(Task.scala:29)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.util.Task.apply$(Task.scala:9)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase$task$2$.apply(Phase.scala:85)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase$$anon$4.run(Phase.scala:94)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase.apply(Phase.scala:41)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase.apply$(Phase.scala:34)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Phase$$anon$4.apply(Phase.scala:92)
import b
^^^^^^^^
[info] ./a.effekt:3:1:   at effekt.Compiler.runFrontend(Compiler.scala:119)
import b
^^^^^^^^
[error] ./a.effekt:3:1: Cannot compile dependency: ./a
import b
^^^^^^^^
[error] ./a.effekt:3:1: Cannot compile dependency: ./b
import b
^^^^^^^^
@b-studios
Copy link
Collaborator

The null probably comes from not implementing getMessage or passing that along (on a custom Exception).

@jiribenes
Copy link
Contributor Author

The null comes from a StackOverflowException not implementing .getMessage which we cannot do anything about.
See #780 for more details.

What is relevant for this issue is that it is, indeed, just a stack overflow. :)

[info] ./a.effekt:3:1: Effekt Compiler Crash: java.lang.StackOverflowError
import b
^^^^^^^^
[info] ./a.effekt:3:1: java.lang.StackOverflowError

@jiribenes jiribenes changed the title Compiler crash on a cyclic import Stack overflow in compiler on a cyclic import Jan 15, 2025
dvdvgt pushed a commit that referenced this issue Jan 15, 2025
Resolves the `Effect Compiler Crash: null` part of #760.
The actual problem there was that `e.getMessage` can return `null` and
it does for... _StackOverflowException_ 🥳.
Looking at the docs, it's recommended to use `e.toString`.

While I was at it, I modified stack trace printing, now we do it
properly by using `.printStackTrace`.

This is very related to #731, I just want to get this out quickly to
unblock other problems.
dvdvgt pushed a commit that referenced this issue Jan 17, 2025
Resolves the `Effect Compiler Crash: null` part of #760.
The actual problem there was that `e.getMessage` can return `null` and
it does for... _StackOverflowException_ 🥳.
Looking at the docs, it's recommended to use `e.toString`.

While I was at it, I modified stack trace printing, now we do it
properly by using `.printStackTrace`.

This is very related to #731, I just want to get this out quickly to
unblock other problems.
EveEme pushed a commit to EveEme/effekt that referenced this issue Jan 20, 2025
Resolves the `Effect Compiler Crash: null` part of effekt-lang#760.
The actual problem there was that `e.getMessage` can return `null` and
it does for... _StackOverflowException_ 🥳.
Looking at the docs, it's recommended to use `e.toString`.

While I was at it, I modified stack trace printing, now we do it
properly by using `.printStackTrace`.

This is very related to effekt-lang#731, I just want to get this out quickly to
unblock other problems.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working errormessage
Projects
None yet
Development

No branches or pull requests

2 participants