Skip to content

Inlined try block breaks pickling tests #4006

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
OlivierBlanvillain opened this issue Feb 16, 2018 · 2 comments
Closed

Inlined try block breaks pickling tests #4006

OlivierBlanvillain opened this issue Feb 16, 2018 · 2 comments

Comments

@OlivierBlanvillain
Copy link
Contributor

class Foo {
  inline def foo: Int = try { 1 } finally println("Hello")
  foo
}
$ dotc tests/allan/Test.scala -Ytest-pickler 
exception occurred while compiling tests/allan/Test.scala
Exception in thread "main" class dotty.tools.dotc.reporting.diagnostic.messages$Error at ?: pickling difference for class Foo in tests/allan/Test.scala, for details:
                   |
                   |  diff before-pickling.txt after-pickling.txt
	at dotty.tools.dotc.reporting.Reporting.error(Reporter.scala:88)
	at dotty.tools.dotc.transform.Pickler.testSame(Pickler.scala:107)
	at dotty.tools.dotc.transform.Pickler.testUnpickler$$anonfun$4(Pickler.scala:99)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.TraversableLike$WithFilter.$anonfun$foreach$1(TraversableLike.scala:789)
	at scala.collection.mutable.HashMap.$anonfun$foreach$1(HashMap.scala:138)
	at scala.collection.mutable.HashTable.foreachEntry(HashTable.scala:236)
	at scala.collection.mutable.HashTable.foreachEntry$(HashTable.scala:229)
	at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:40)
	at scala.collection.mutable.HashMap.foreach(HashMap.scala:138)
	at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:788)
	at dotty.tools.dotc.transform.Pickler.testUnpickler(Pickler.scala:100)
	at dotty.tools.dotc.transform.Pickler.runOn(Pickler.scala:83)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:123)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:18)
	at scala.compat.java8.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:191)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:136)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:141)
	at scala.compat.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:88)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:143)
	at dotty.tools.dotc.Run.compileSources(Run.scala:94)
	at dotty.tools.dotc.Run.compile(Run.scala:78)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:29)
	at dotty.tools.dotc.Driver.process(Driver.scala:127)
	at dotty.tools.dotc.Driver.process(Driver.scala:96)
	at dotty.tools.dotc.Driver.process(Driver.scala:108)
	at dotty.tools.dotc.Driver.main(Driver.scala:135)
	at dotty.tools.dotc.Main.main(Main.scala
@odersky
Copy link
Contributor

odersky commented Feb 18, 2018

I would classify pickling errors in quoting, if they manifest themselves as differences before and after pickling.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 19, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2018
@nicolasstucki
Copy link
Contributor

nicolasstucki commented Feb 20, 2018

Decompiling the class shows that the inlined call to foo has a catch/case instead of a finally.
The current encoding for it is ambiguous as we have no way to determine if we need to read66:SHAREDterm 42 as a case or a finally (reading the cases).

    62:         TRY(4)
    64:           SHAREDterm 38
    66:           SHAREDterm 42
================================================================================
./Foo.class
--------------------------------------------------------------------------------
package <empty> {
  class Foo() extends Object() {
    @(try
      {
        1
      }
     finally println("Hello")) inline def foo: Int =
      try
        {
          1
        }
       finally println("Hello")
    /* inlined from Foo*/
      {
        try
          {
            1
          }
         catch
          {
            case println => "Hello"
          }
      }
  }
}
--------------------------------------------------------------------------------
Names:
   0: ASTs
   1: <empty>
   2: Foo
   3: <init>
   4: java
   5: lang
   6: java[Qualified . lang]
   7: Object
   8: java[Qualified . lang][Qualified . Object]
   9: <init>[Signed Signature(List(),java.lang.Object)]
  10: Unit
  11: scala
  12: foo
  13: Int
  14: println
  15: scala[Qualified . Unit]
  16: println[Signed Signature(List(java.lang.Object),scala.Unit)]
  17: Predef
  18: Hello
  19: SourceFile
  20: annotation
  21: scala[Qualified . annotation]
  22: internal
  23: scala[Qualified . annotation][Qualified . internal]
  24: scala[Qualified . annotation][Qualified . internal][Qualified . SourceFile]
  25: String
  26: java[Qualified . lang][Qualified . String]
  27: <init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile)]
  28: Foo.scala
  29: Positions

Trees:
start = Addr(0), base = 227, current = Addr(0), end = Addr(83)
83 bytes of AST, base = Addr(0)

     0: PACKAGE(81)
     2:   TERMREFpkg 1 [<empty>]
     4:   TYPEDEF(77) 2 [Foo]
     7:     TEMPLATE(59)
     9:       APPLY(7)
    11:         SELECT 9 [<init>[Signed Signature(List(),java.lang.Object)]]
    13:           NEW
    14:             TYPEREF 7 [Object]
    16:               TERMREFpkg 6 [java[Qualified . lang]]
    18:       DEFDEF(7) 3 [<init>]
    21:         PARAMS(0)
    23:         TYPEREF 10 [Unit]
    25:           TERMREFpkg 11 [scala]
    27:       DEFDEF(24) 12 [foo]
    30:         IDENTtpt 13 [Int]
    32:           TYPEREF 13 [Int]
    34:             TERMREFpkg 11 [scala]
    36:         TRY(14)
    38:           BLOCK(2)
    40:             INTconst 1
    42:           APPLY(8)
    44:             TERMREF 16 [println[Signed Signature(List(java.lang.Object),scala.Unit)]]
    46:               TERMREF 17 [Predef]
    48:                 SHAREDtype 25
    50:             STRINGconst 18 [Hello]
    52:         INLINE
    53:       INLINED(13)
    55:         IDENTtpt 2 [Foo]
    57:           TYPEREFsymbol 4
    59:             THIS
    60:               TYPEREFpkg 1 [<empty>]
    62:         TRY(4)
    64:           SHAREDterm 38
    66:           SHAREDterm 42
    68:     ANNOTATION(13)
    70:       TYPEREF 19 [SourceFile]
    72:         TERMREFpkg 23 [scala[Qualified . annotation][Qualified . internal]]
    74:       APPLY(7)
    76:         SELECT 27 [<init>[Signed Signature(List(java.lang.String),scala.annotation.internal.SourceFile)]]
    78:           NEW
    79:             SHAREDtype 70
    81:         STRINGconst 28 [Foo.scala]
    83: 50 position bytes:
         0: 0 .. 78
         4: 0 .. 78
         7: 14 .. 76
        13: 6 .. 9
        14: 6 .. 6
        18: 14 .. 14
        23: 14 .. 14
        27: 14 .. 70
        30: 30 .. 33
        36: 36 .. 70
        38: 40 .. 45
        40: 42 .. 43
        42: 54 .. 70
        44: 54 .. 61
        50: 62 .. 69
        55: 73 .. 76
        62: 73 .. 76
--------------------------------------------------------------------------------

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2018
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 20, 2018
nicolasstucki added a commit that referenced this issue Feb 22, 2018
Fix #4006: Avoid ambiguity between SHAREDterm cases and finally
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