Skip to content

Fix cyclic reference errors in collection strawman #2914

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

Merged
merged 4 commits into from
Aug 2, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ Standard-Section: "ASTs" TopLevelStat*
BIND Length boundName_NameRef bounds_Type
// for type-variables defined in a type pattern
BYNAMEtype underlying_Type
LAZYref underlying_Type
POLYtype Length result_Type NamesTypes
METHODtype Length result_Type NamesTypes // needed for refinements
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
Expand Down Expand Up @@ -256,7 +257,7 @@ object TastyFormat {
final val OBJECTCLASS = 40

final val SIGNED = 63

final val firstInternalTag = 64
final val IMPLMETH = 64

Expand Down Expand Up @@ -322,6 +323,7 @@ object TastyFormat {
final val PROTECTEDqualified = 105
final val RECtype = 106
final val SINGLETONtpt = 107
final val LAZYref = 108

final val IDENT = 112
final val IDENTtpt = 113
Expand Down Expand Up @@ -512,6 +514,7 @@ object TastyFormat {
case DOUBLEconst => "DOUBLEconst"
case STRINGconst => "STRINGconst"
case RECtype => "RECtype"
case LAZYref => "LAZYref"

case IDENT => "IDENT"
case IDENTtpt => "IDENTtpt"
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class TreePickler(pickler: TastyPickler) {
case tpe: ParamRef =>
assert(pickleParamRef(tpe), s"orphan parameter reference: $tpe")
case tpe: LazyRef =>
writeByte(LAZYref)
pickleType(tpe.ref)
}

Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,11 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
RecType(rt => registeringType(rt, readType()))
case RECthis =>
RecThis(readTypeRef().asInstanceOf[RecType])
case LAZYref =>
val rdr = fork
def readUnderlying() = rdr.readType()
skipTree()
LazyRef(readUnderlying)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means LazyRefs will keep the context from which they were unpickled around, if these LazyRefs are subsequently stored in some cache, that could lead to space leaks, no?

Copy link
Contributor Author

@odersky odersky Jul 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, correct. Maybe the best option is to allow a context to be passed into a LazyRef completer. In the case of unpickling, this is fine; we don't need to hang on to more than the reader (I think, at least that's what we do for the other completers).

case SHARED =>
val ref = readAddr()
typeAtAddr.getOrElseUpdate(ref, forkAt(ref).readType())
Expand Down