-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Drop empty companion objects #1075
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
Add operations to NameOps to detect and produce names for lazy locals. @DarkDimius Maybe there is already another way to do this? I could not find it.
The underlying problem on MacOS/Windows remains: We have a class `B` and an object `b` in the same scope. We used to get a conflict on `B$/b$` because we created an empty companion object for `B`. Now we get a conflict for `B/b`, because the `b` object creates to classes: `b.class` an `b$.class` and `b.class` clashes with `B.class`.
If the object was explicitly written, it might be referenced, even if it is empty.
@@ -367,7 +367,7 @@ class LazyVals extends MiniPhaseTransform with IdentityDenotTransformer { | |||
appendOffsetDefs += (companion.moduleClass -> new OffsetInfo(List(offsetTree), ord)) | |||
} | |||
|
|||
val containerName = ctx.freshName(x.name ++ StdNames.nme.LAZY_LOCAL).toTermName |
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.
@DarkDimius This is just DRY in order not to do the same low-level name plumbing over and over again.
@DarkDimius This was unexpectedly messy. It makes me wonder whether having synthesized companion objects is worth it. Could we not just use static members everywhere? We'd shed a ton |
I'm not sure I understood what you're proposing. Are you proposing to deprecate value classes and revert to previous implementation of lazy vals? |
No, I am proposing neither of that. |
I mean: Instead putting things in companion objects, make them static members of their class. |
@odersky, it seems to me that instances of synthetic objects are never I guess we can compile members of synthetic objects into static methods on On 13 February 2016 11:02:35 odersky [email protected] wrote:
|
Yes, but why do we put synthetic members into companion objects in the On Sat, Feb 13, 2016 at 3:01 PM, Dmitry Petrashko [email protected]
Martin Odersky |
I believe it can be implemented with less pain using functionality from
Because it allows to ensure correct scoping using Ycheck, because those I'm convinced that's its fundamentally better to handle them entirely in I would have agreed if we had full control of code that we make static. I have a simpler proposal, though less principled than @static: we can On 13 February 2016 15:38:25 odersky [email protected] wrote:
|
OK, I understand the arguments. Alternatives are not necessarily better. Let's get this in, it is quite workable as is. |
Agreed. LGTM |
Drop empty companion objects
case TypeDef(_, impl: Template) if tree.symbol.is(SyntheticModule) && | ||
tree.symbol.companionClass.exists && | ||
impl.body.forall(_.symbol.isPrimaryConstructor) => | ||
println(i"removing ${tree.symbol}") |
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.
println left in code.
I'll make a pr to remove it.
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.
It's already removed in another PR of mine. So it should go away by itself
soon.
On Thu, Feb 18, 2016 at 11:23 AM, Dmitry Petrashko <[email protected]
wrote:
In src/dotty/tools/dotc/transform/DropEmptyCompanions.scala
#1075 (comment):
- * level, so we know that all objects moved by LambdaLift and Flatten have arrived
- * at their destination.
- */
+class DropEmptyCompanions extends MiniPhaseTransform { thisTransform =>- import ast.tpd._
- override def phaseName = "dropEmpty"
- override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Flatten])
- override def transformPackageDef(pdef: PackageDef)(implicit ctx: Context, info: TransformerInfo) = {
- /** Is
tree
an empty companion object? */- def isEmptyCompanion(tree: Tree) = tree match {
case TypeDef(_, impl: Template) if tree.symbol.is(SyntheticModule) &&
tree.symbol.companionClass.exists &&
impl.body.forall(_.symbol.isPrimaryConstructor) =>
println(i"removing ${tree.symbol}")
println left in code.
I'll make a pr to remove it.—
Reply to this email directly or view it on GitHub
https://github.com/lampepfl/dotty/pull/1075/files#r53295488.
Martin Odersky
EPFL
Review by @DarkDimius