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

case class overriding a type causes sbt component used by compiler to throw stack overflow #22026

Open
tribbloid opened this issue Nov 26, 2024 · 4 comments
Labels
itype:bug itype:performance stat:needs investigation Hard to to tell much without investigating this further. Needs a spike.

Comments

@tribbloid
Copy link

Compiler version

3.5.2

Minimized code

trait TypeBound {

  type Min
  type Max >: Min
}

object TypeBound {

  type Pinpoint = TypeBound { type Max = Min }
}

object HasPoly1 {

  trait Poly1[B <: TypeBound] {

    type Refined[Sub <: B]

    def refine[Sub <: B](sub: Sub): Refined[Sub]
  }

  object Poly1 {

    type Concrete = Poly1[? <: TypeBound.Pinpoint] // can only refine using a concrete type, not a type bound

    case class Example1() extends Poly1[TypeBound.Pinpoint] {

      case class Refined[Sub <: TypeBound.Pinpoint](sub: Sub) {

        final val fn: sub.Max => Seq[sub.Max] = { v =>
          Seq(v)
        }
      }

      def refine[Sub <: TypeBound.Pinpoint](sub: Sub): Refined[Sub] = Refined[Sub](sub)
    }
  }
}

Output

Cause: java.lang.StackOverflowError
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:377)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toProjection$1(ProtobufWriters.scala:393)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:449)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toTypeAlias$1(ProtobufWriters.scala:553)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toClassDefinition(ProtobufWriters.scala:580)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$1(ProtobufWriters.scala:377)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:377)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$3(ProtobufWriters.scala:379)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:379)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toProjection$1(ProtobufWriters.scala:393)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:449)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toTypeAlias$1(ProtobufWriters.scala:553)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toClassDefinition(ProtobufWriters.scala:580)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$1(ProtobufWriters.scala:377)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:377)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$3(ProtobufWriters.scala:379)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:379)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toProjection$1(ProtobufWriters.scala:393)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:449)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toTypeAlias$1(ProtobufWriters.scala:553)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toClassDefinition(ProtobufWriters.scala:580)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$1(ProtobufWriters.scala:377)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:377)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$3(ProtobufWriters.scala:379)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:379)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toProjection$1(ProtobufWriters.scala:393)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:449)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toTypeAlias$1(ProtobufWriters.scala:553)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toClassDefinition(ProtobufWriters.scala:580)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$1(ProtobufWriters.scala:377)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:377)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$3(ProtobufWriters.scala:379)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toStructure(ProtobufWriters.scala:379)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:444)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toProjection$1(ProtobufWriters.scala:393)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toType(ProtobufWriters.scala:449)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toTypeAlias$1(ProtobufWriters.scala:553)
	at sbt.internal.inc.binary.converters.ProtobufWriters.toClassDefinition(ProtobufWriters.scala:580)
	at sbt.internal.inc.binary.converters.ProtobufWriters.$anonfun$toStructure$1(ProtobufWriters.scala:377)
...

on scastie it will time out:

https://scastie.scala-lang.org/tribbloid/XNl7bfiyRpyqNzbhZOnI8w/2

Expectation

Simple program, should compile in 3 seconds. Maybe a hidden bug in Protobuf

@tribbloid tribbloid added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 26, 2024
@Gedochao Gedochao added itype:performance and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Nov 26, 2024
@Gedochao
Copy link
Contributor

Seems to compile excessively long, but succeed on my machine.
Additionally, it seems to hang when compiled with Bloop.
So something is definitely up.

@Gedochao Gedochao added the stat:needs investigation Hard to to tell much without investigating this further. Needs a spike. label Nov 26, 2024
@Gedochao
Copy link
Contributor

Side note, compiling this with Scala CLI using the build server (Bloop) will make Bloop hang, forcing one to restart it.
This is quite bad. 😐
cc @tgodzik

@tgodzik
Copy link
Contributor

tgodzik commented Nov 26, 2024

Might be oom before the stack overflow actually catches up.

@tgodzik
Copy link
Contributor

tgodzik commented Nov 26, 2024

Looks like compilation indeed hangs, but you don't have to kill Bloop, at least in my case it wasn't necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
itype:bug itype:performance stat:needs investigation Hard to to tell much without investigating this further. Needs a spike.
Projects
None yet
Development

No branches or pull requests

3 participants