-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Use a final module instance field, assigned in <clinit> where possible #6523
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
Conversation
|
Implementation could be widened to cover Predef In general it would be nice to be able to mark pure behaviours (that don't access this) in some way to enforce the limit at compile time. or even make these implementatation methods static? (this that is not too offensive to scala devs 🔥) - rorygraves#19 |
b23cea3 to
b7887bb
Compare
|
@mkeskells The constructor matters, not just the parents, and |
b7887bb to
85c1764
Compare
lrytz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good otherwise. Maybe add a test/junit/scala/lang/modules/BytecodeTest.scala?
src/library/scala/Predef.scala
Outdated
| object Predef extends LowPriorityImplicits { | ||
| def main(args: Array[String]): Unit = { | ||
|
|
||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's some leftover here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops!
For modules without side effects in their constructors, and that only extend Object of FunctionN, we can defer assignment of the module instance field, and make that field final.
85c1764 to
443e175
Compare
|
I've added a test which showed up a problem in the implementation (pure case class companions extends |
|
A more general approach is proposed in forax/exotic, which uses |
|
@retronym did you confirm if that would well on Java 8. The exotics library doesn't compile in Java 8, and some of the techniques that I have back-ported are slow until Java 9. I have not catalogued which ones though |
|
I'm not planning to pursue the |
For modules without side effects in their constructors, and that only extend
Objector(Abstract)FunctionN, we can defer assignment of the module instance field, and make that field final.