Skip to content

Owner discrepancy when compiling from TASTY #3816

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
nicolasstucki opened this issue Jan 12, 2018 · 3 comments
Closed

Owner discrepancy when compiling from TASTY #3816

nicolasstucki opened this issue Jan 12, 2018 · 3 comments

Comments

@nicolasstucki
Copy link
Contributor

nicolasstucki commented Jan 12, 2018

Compiling the following minimization of tests/pos/NoCyclicReference.scala with -Ytest-pickler

trait Iterable { self =>
  type CC <: Iterable { type CC = self.CC }
}

fails with

> dotc -Ytest-pickler Test.scala
exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: Cyclic reference while unpickling definition at address 29 in unit null
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:36)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedDef(TreeUnpickler.scala:637)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$Completer.complete(TreeUnpickler.scala:91)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:246)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeInfo$1(SymDenotations.scala:209)
	at dotty.tools.dotc.core.SymDenotations$SymDenotation.info(SymDenotations.scala:211)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1070)
	at dotty.tools.dotc.core.Denotations$SingleDenotation.computeAsSeenFrom(Denotations.scala:1063)
	at dotty.tools.dotc.core.Denotations$PreDenotation.asSeenFrom(Denotations.scala:131)
	at dotty.tools.dotc.core.SymDenotations$ClassDenotation.findMember(SymDenotations.scala:1599)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:514)
	at dotty.tools.dotc.core.Types$Type.goAnd$1(Types.scala:646)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:532)
	at dotty.tools.dotc.core.Types$Type.goThis$1(Types.scala:615)
	at dotty.tools.dotc.core.Types$Type.go$1(Types.scala:518)
	at dotty.tools.dotc.core.Types$Type.findMember(Types.scala:658)
	at dotty.tools.dotc.core.Types$Type.memberExcluding(Types.scala:497)
	at dotty.tools.dotc.core.Types$Type.member(Types.scala:482)
	at dotty.tools.dotc.core.tasty.TreeUnpickler.accessibleDenot$1(TreeUnpickler.scala:906)
	at dotty.tools.dotc.core.tasty.TreeUnpickler.dotty$tools$dotc$core$tasty$TreeUnpickler$TreeReader$$_$readSimpleTerm$1$$anonfun$1(TreeUnpickler.scala:927)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.completeSelect$1(TreeUnpickler.scala:897)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readSimpleTerm$1(TreeUnpickler.scala:927)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTerm(TreeUnpickler.scala:1051)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTpt(TreeUnpickler.scala:1058)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readNewDef(TreeUnpickler.scala:719)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedDef(TreeUnpickler.scala:643)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStat(TreeUnpickler.scala:823)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStats$$anonfun$1(TreeUnpickler.scala:861)
	at dotty.tools.dotc.core.tasty.TastyReader.until(TastyReader.scala:125)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readIndexedStats(TreeUnpickler.scala:861)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readStats(TreeUnpickler.scala:865)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readLengthTerm$1(TreeUnpickler.scala:1018)
	at dotty.tools.dotc.core.tasty.TreeUnpickler$TreeReader.readTerm(TreeUnpickler.scala:1051)
...
@nicolasstucki
Copy link
Contributor Author

Same issue for affects tests/pos/i1795.scala

@smarter
Copy link
Member

smarter commented Jan 12, 2018

We can figure out what's going on by enabling pickle printing and adding some indentation to the printed messages (https://github.com/dotty-staging/dotty/commits/unpickle-debug). The Tasty section looks like

     0: PACKAGE(72)
     2:   TERMREFpkg 1 [<empty>]
     4:   TYPEDEF(68) 2 [Iterable]
     7:     TEMPLATE(49)
     9:       TYPEREF 3 [Object]
    11:         TERMREFpkg 6 [java[Qualified . lang]]
    13:       SELFDEF 7 [self]
    15:         TYPEREFsymbol 4
    17:           THIS
    18:             TYPEREFpkg 1 [<empty>]
    20:       DEFDEF(7) 8 [<init>]
    23:         PARAMS(0)
    25:         TYPEREF 9 [Unit]
    27:           TERMREFpkg 10 [scala]
    29:       TYPEDEF(27) 11 [CC]
    32:         TYPEBOUNDStpt(24)
    34:           TYPEREF 12 [Nothing]
    36:             SHARED 27
    38:           REFINEDtpt(18)
    40:             IDENTtpt 2 [Iterable]
    42:               SHARED 15
    44:             TYPEDEF(12) 11 [CC]
    47:               TYPEBOUNDStpt(9)
    49:                 SHARED 34
    51:                 SELECTtpt 11
    53:                   QUALTHIS
    54:                     IDENTtpt 2 [Iterable]
    56:                       SHARED 15

and the unpickling logs end with:

reading def of CC at Addr(29)
  reading term TYPEBOUNDStpt at Addr(32)
    reading type TYPEREF at Addr(34)
      reading type SHARED at Addr(36)
        reading type TERMREFpkg at Addr(27)
    reading term REFINEDtpt at Addr(38)
      refineCls: class <refinement> 3420
      reading term IDENTtpt at Addr(40)
        reading type SHARED at Addr(42)
          reading type TYPEREFsymbol at Addr(15)
            reading type THIS at Addr(17)
              reading type TYPEREFpkg at Addr(18)
      creating symbol CC at Addr(44) with flags 
      reading def of CC at Addr(44)
        reading term TYPEBOUNDStpt at Addr(47)
          reading type SHARED at Addr(49)
            reading type TYPEREF at Addr(34)
              reading type SHARED at Addr(36)
          reading term SELECTtpt at Addr(51)
            reading term QUALTHIS at Addr(53)
              reading term IDENTtpt at Addr(54)
                reading type SHARED at Addr(56)
            reading def of CC at Addr(29)
              reading term TYPEBOUNDStpt at Addr(32)
                reading type TYPEREF at Addr(34)
                  reading type SHARED at Addr(36)
                reading term REFINEDtpt at Addr(38)
                  refineCls: class <refinement> 3422
                  reading term IDENTtpt at Addr(40)
                    reading type SHARED at Addr(42)
Exception in thread "main" java.lang.AssertionError: assertion failed: owner discrepancy for type CC#3421, expected: class <refinement>#3422, found: class <refinement>#3420

Notice that there's a loop, we start with reading def of CC at Addr(29) which requires reading def of CC at Addr(44) which itself requires reading def of CC at Addr(29). Where we end up completing the outer type CC <: ... a second time (maybe we should use the Touched flag to fail early when this happen?).

This doesn't happen when typing from source because completing a TypeDef involves some complicated logic to avoid cyclic references: https://github.com/lampepfl/dotty/blob/fc983f72e9b760e6c7d8394f9f8f303ebc878417/compiler/src/dotty/tools/dotc/typer/Namer.scala#L1170-L1212 We may need something similar for unpickling.

@smarter
Copy link
Member

smarter commented Jan 25, 2018

This (or something like this) is now affecting the collection-strawman: #3816 so I'm raising the priority to blocker. I'm too swamped to work on this now, so assigning @odersky .

odersky added a commit to dotty-staging/dotty that referenced this issue Jan 29, 2018
smarter pushed a commit to dotty-staging/dotty that referenced this issue Feb 2, 2018
@odersky odersky closed this as completed in fae14bb Feb 2, 2018
odersky added a commit that referenced this issue Feb 2, 2018
Fix #3816: Protect against cycles when unpickling hk types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants