Skip to content

Conversation

@retronym
Copy link
Member

@retronym retronym commented Jul 8, 2012

scala-internals thread

The effect of the change is best described by the diff of flatten.check

Review by @paulp, @odersky

  • Can you suggest additional interesting cases for test/files/run/flatten.scala?
  • Do we care that by unnesting the names we make it harder to mentally link the mangled name to its source code? (Incidentally, it would be great if we could teach YourKit to do this for us automatically, to save us either guessing / messing around with javap to figure it out).
  • I've done this for $anonFun, $anon: is there anything else that could have the same treatment?
  • The code to walk the rawowner chain was a bit fiddly to write and should be scrutinized. I didn't find an existing method on Symbol that did what I needed.

References SI-3623.

retronym added 2 commits July 8, 2012 22:54
The following commit will change that phase to elide the noisy
`$anon1$anon2` intermediaries from flat names of nested anonymous
functions and classes.
This avoids ugly class names like Foo$anon1$anon2$anon3 when
defining anonymous functions or classes in a nested location.
@scala-jenkins
Copy link

@scala-jenkins
Copy link

@retronym
Copy link
Member Author

retronym commented Jul 9, 2012

Build failure. SIGILL, que?

  [partest] testing: [...]/files/jvm/serialization-new.scala                      [FAILED]
  ...
  [partest] 
  [partest] x10 = Monday
  [partest] y10 = Monday
  [partest] x10 eq y10: true, y10 eq x10: true
  [partest] x10 equals y10: true, y10 equals x10: true
  [partest] 
  [partest] x9 eq x10: false, x10 eq x9: false
  [partest] x9 equals x10: false, x10 equals x9: false
  [partest] x9 eq y10: false, y10 eq x9: false
  [partest] x9 equals y10: false, y10 equals x9: false
  [partest] 
  [partest] f1 = <na>
  [partest] _f1 = <na>
  [partest] f1(2): 4, _f1(2): 4
  [partest] 
  [partest] xs0 = List(1, 2, 3)
  [partest] _xs0 = List(1, 2, 3)
  [partest] xs0 eq _xs0: false, _xs0 eq xs0: false
  [partest] xs0 equals _xs0: true, _xs0 equals xs0: true
  [partest] 
  [partest] xs1 = List()
  [partest] _xs1 = List()
  [partest] xs1 eq _xs1: true, _xs1 eq xs1: true
  [partest] 
  [partest] o1 = None
  [partest] _o1 = None
  [partest] o1 eq _o1: true, _o1 eq o1: true
  [partest] 
  [partest] o2 = Some(1)
  [partest] _o2 = Some(1)
  [partest] o2 eq _o2: false, _o2 eq o2: false
  [partest] o2 equals _o2: true, _o2 equals o2: true
  [partest] 
  [partest] s1 = 'hello
  [partest] _s1 = 'hello
  [partest] s1 eq _s1: true, _s1 eq s1: true
  [partest] s1 equals _s1: true, _s1 equals s1: true
  [partest] 
  [partest] t1 = (BannerLimit,12345)
  [partest] _t1 = (BannerLimit,12345)
  [partest] t1 eq _t1: false, _t1 eq t1: false
  [partest] t1 equals _t1: true, _t1 equals t1: true
  [partest] 
  [partest] x = BitSet(1, 2)
  [partest] y = BitSet(1, 2)
  [partest] x equals y: true, y equals x: true
  ...
  [partest] x = UnrolledBuffer(one, two)
  [partest] y = UnrolledBuffer(one, two)
  [partest] x equals y: true, y equals x: true
  [partest] 
  [partest] x = ParArray(abc, def, etc)
  [partest] y = ParArray(abc, def, etc)
  [partest] #
  [partest] # A fatal error has been detected by the Java Runtime Environment:
  [partest] #
  [partest] #  SIGILL (0x4) at pc=0xf77173f2, pid=28430, tid=2922589040
  [partest] #
  [partest] # JRE version: 6.0_31-b04
  [partest] # Java VM: Java HotSpot(TM) Server VM (20.6-b01 mixed mode linux-x86 )
  [partest] [thread -1372046480 also had an error]
  [partest] x equals y: true, y equals x: true
  [partest] # Problematic frame:
  [partest] # C  [libc.so.6+0x1563f2]  __libc_thread_freeres+0x36672
  [partest] #
  [partest] # An error report file with more information is saved as:
  [partest] # /localhome/hudson/workspace/pr-scala-testsuite-linux-opt/hs_err_pid28430.log
  [partest] #
  [partest] # If you would like to submit a bug report, please visit:
  [partest] #   http://java.sun.com/webapps/bugreport/crash.jsp

Works for me:


topic/elide-anon ~/code/scala ./test/partest test/files/jvm/serialization.scala  
Testing individual files
testing: [...]/files/jvm/serialization.scala                          [  OK  ]

All of 1 tests were successful (elapsed time: 00:00:12)
topic/elide-anon ~/code/scala ./test/partest test/files/jvm/serialization-new.scala 

Testing individual files
testing: [...]/files/jvm/serialization-new.scala                      [  OK  ]

All of 1 tests were successful (elapsed time: 00:00:11)

PLS REBUILD ALL

@scala-jenkins
Copy link

@scala-jenkins
Copy link

Under the new scheme, they retain the method suffix added in SI-101.
@scala-jenkins
Copy link

@scala-jenkins
Copy link

@ghost ghost assigned paulp Jul 11, 2012
Copy link
Contributor

Choose a reason for hiding this comment

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

I never really figured out whether it was intentional or not, but ANON_CLASS_NAME is a substring of ANON_FUN_NAME, so the above is redundant. You can just check for ANON_CLASS_NAME. Which has obvious unintended consequences:

package foo

object bar {
  class anonymize { }
}
// scala> afterFlatten(intp.terms("foo").info.members filter (_.isAnonymousClass))
// res0: List[$r.intp.global.Symbol] = List(anonymous class bar$anonymize)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, it's pretty loose as it stands. I was trying not to rely on that quirk, but that at least warrants a comment.

@retronym
Copy link
Member Author

@odersky Anonymous functions owned by a method are suffixed with the method name; this still happens after this patch (see the expanded test in 9629175).

The current scheme seems to stop short of being useful for serialization/JRebel: flat names are prefixed with owner chain, but the unflattened name is used to generate fresh names in flatten, meaning that the names of all anonymous classes and of all non-method-owned anonymous functions are sensitive to the overall position in the compilation unit.

I was also considering appending the name of the first parent class to the generated name of an anonymous class, e.g. $anonRunnable. (This is problematic for a parent class named fun, though!).

I'm going to close this PR, implement some refinements, and then discuss further on scala-internals. This can wait until after 2.10.

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.

4 participants