Skip to content

[PROOF-OF-CONCEPT/DO NOT MERGE] Avoid forcing type aliases to get their typeParams #981

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
wants to merge 1 commit into from

Conversation

smarter
Copy link
Member

@smarter smarter commented Nov 27, 2015

This is a strawman proposal for fixing #970, before this commit, the
following failed with a cyclic reference error:

dotc B.scala\
./scala-scala/src/library/scala/collection/immutable/Seq.scala\
./scala-scala/src/library/scala/package.scala\
./scala-scala/src/library/scala/collection/GenSeqLike.scala\
./scala-scala/src/library/scala/collection/SeqLike.scala\
./scala-scala/src/library/scala/collection/generic/GenSeqFactory.scala

where B.scala is defined as:

object B{
  def main(args: Array[String]): Unit = {
    val s = List(1,2,3)
    ()
  }
}

Here's what I think is happening:

  1. Unpickling a Scala2 TypeRef requires us to perform type application.
    (Scala2Unpickler#readType)
  2. To apply a TypeAlias to some arguments, we first need to determine its
    type parameters.
    (TypeApplications#appliedTo and TypeApplications#typeParams)
  3. To do this, we look at the type parameters of the underlying type of
    the TypeAlias, this requires completing the TypeAlias.
  4. If the TypeAlias is defined in a source tree and not unpickled, this
    forces us to typecheck its right-hand side.
    (Namer#Completer#typeSig)
  5. In turns, this forces various classes to be completed, which might
    themselves refer indirectly to type aliases, forcing even more
    stuff.

This commit is a hacky way to avoid 3. by only completing the type parameters
of a type alias instead of completing the whole type alias when we don't
need it. Let me know if you think the basic idea is sound or not and if
you can think of a nicer way to implement it!

CC @odersky

This is a strawman proposal for fixing scala#970, before this commit, the
following fails with a cyclic reference error:

dotc B.scala\
./scala-scala/src/library/scala/collection/immutable/Seq.scala\
./scala-scala/src/library/scala/package.scala\
./scala-scala/src/library/scala/collection/GenSeqLike.scala\
./scala-scala/src/library/scala/collection/SeqLike.scala\
./scala-scala/src/library/scala/collection/generic/GenSeqFactory.scala

where B.scala is defined as:
object B{
  def main(args: Array[String]): Unit = {
    val s = List(1,2,3)
    ()
  }
}

Here's what I think is happening:
1. Unpickling a Scala2 TypeRef requires us to perform type application.
   (`Scala2Unpickler#readType`)
2. To apply a TypeAlias to some arguments, we first need to determine its
   type parameters.
   (`TypeApplications#appliedTo` and `TypeApplications#typeParams`)
3. To do this, we look at the type parameters of the underlying type of
   the TypeAlias, this requires completing the TypeAlias.
4. If the TypeAlias is defined in a source tree and not unpickled, this
   forces us to typecheck its right-hand side.
   (`Namer#Completer#typeSig`)
5. In turns, this forces various classes to be completed, which might
   themselves refer indirectly to type aliases, forcing even more
   stuff.

This commit is a hacky way to avoid 3. by only completing the type parameters
of a type alias instead of completing the whole type alias when we don't
need it. Let me know if you think the basic idea is sound or not and if
you can think of a nicer way to implement it!
@odersky
Copy link
Contributor

odersky commented Jan 15, 2016

Superseded by #1027

@odersky odersky closed this Jan 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants