--
Do you know where the latest version currently is? I would have at least a look at it to see how hard it would be to resurrect, update it for the current version and figure out which issues remain.
Being stuck without @static is pretty annoying because it seems to be the cleanest way to emit static members, which is what currently bocks my work on enums.
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group, send email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I think we've come to the conclusion that the old approach is doomed because of initialization issues.
We care a lot about user experience and we do not indent to ship features that make it easy to shoot yourself in foot.
Hi Grzegorz, hi Adriaan!We care a lot about user experience and we do not indent to ship features that make it easy to shoot yourself in foot.
Well, it wouldn't have been exposed to users anyway? (It would have been something like scala[private], or am I mistaken?)
But I agree that it doesn't seem to be in an usable state right now.
So what options remain for the enum use-case https://docs.google.com/document/d/1mIKml4sJzezL_-iDJMmcAKmavHb9axjYJos_7UMlWJ8/edit#heading=h.duxj33qyodsd (DRAFT)?
I don't think that adding yet another special case for emitting static members in the compiler is a workable approach. :-/
The @static as was considered a few months ago was making the situation a lot worse and that's why it got dropped in the end.
The problem is tricky to be solved in general. May you elaborate why do you need statics in the first place? Why fields in companion object are not good enough?
The @static as was considered a few months ago was making the situation a lot worse and that's why it got dropped in the end.
As far as I have seen now, it wouldn't have worked anyway because the annotation would have been restricted to objects and disallowed in classes.
The problem is tricky to be solved in general. May you elaborate why do you need statics in the first place? Why fields in companion object are not good enough?
The rules are made by the JDK, just like the static hack in scalac for Parceable is required by Android. It just won't work if the implementation doesn't follow the rules.
And I can't emit a companion object with macros anyway, otherwise I would have tried it and hoped that the static forwarders would be enough.
I see. I think exploring that space (macros) is better idea because it should be easier to fix it there. Scalac doesn't really have concept of static and I expect a lot of problems (really difficult ones) if you try to introduce it.
I think we've come to the conclusion that the old approach is doomed because of initialization issues.
The alternative approach suggested by Martin (IIRC) is to generate the implementation for methods in a @static companion objectin the static methods of the companion object's class, with forwarders defined in the module class (the one suffixed with $)
object O { def foo = ??? }
becomes
class O { public static void foo() { ??? } }class O$ { public void foo() { return MODULE$.foo() }; public static final O$ MODULE$ = this; }
the issues with this:- need accessors to access protected methods in O's super classes- name clashes between static and non-static methods--
On Mon, Jan 28, 2013 at 2:52 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:
Do you know where the latest version currently is? I would have at least a look at it to see how hard it would be to resurrect, update it for the current version and figure out which issues remain.
Being stuck without @static is pretty annoying because it seems to be the cleanest way to emit static members, which is what currently bocks my work on enums.
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group, send email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group, send email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
-- Aleksandar Prokopec, Doctoral Assistant LAMP, IC, EPFL http://people.epfl.ch/aleksandar.prokopec
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
Would initialization issues still be a problem if the @static annotations was placed on members of the companion class instead of on the members of a companion object?
Seems to me that it's much easier to reason about initialization of these fields then, since these the class Foo and its companion object Foo appear as separate entities.
On 1/29/13 12:37 AM, Adriaan Moors wrote:
I think we've come to the conclusion that the old approach is doomed because of initialization issues.
Would initialization issues still be a problem if the @static annotations was placed on members of the companion class instead of on the members of a companion object?
I.e., this:
class Foo {
@static var bar = 1
}
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
That is actually worse than putting it into the object, because instead of being intermingled with the MODULE constructor (which is run by the static initializer) it is now intermingled with the class’ normal constructor, which is not related at all.
How do you explain to users that “this” is not available in certain statements?
That is actually worse than putting it into the object, because instead of being intermingled with the MODULE constructor (which is run by the static initializer) it is now intermingled with the class’ normal constructor, which is not related at all.I'm not sure this is the case. @static stuff should be initialized when the class is first referenced, that's the job of the static initializer of the class. Where would the class constructor get involved?
How do you explain to users that “this” is not available in certain statements?I would propose something along the lines of “if it is static, this is not available”.
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
I think before we do a hack like this (and everything needing an annotation is essentially a hack), we should seriously consider the alternative: always generate java-static fields and methods for members of a globally accessible object. It would make all problems go away, will probably give us a modest performance gain, and is from the user standpoint by far the simplest. It's also the hardest to implement but that's the right tradeoff IMO.
I think before we do a hack like this (and everything needing an annotation is essentially a hack), we should seriously consider the alternative: always generate java-static fields and methods for members of a globally accessible object. It would make all problems go away, will probably give us a modest performance gain, and is from the user standpoint by far the simplest. It's also the hardest to implement but that's the right tradeoff IMO.
Sounds like an interesting idea. As usual, my concerns about the impact on class-file size apply. :-)
--
If anything, I'd expect it to reduce both bytecode size and class count.For methods that can be expressed as statics (e.g. they're not inherited), there would be no need to generate the static forwarders.In cases where *all* the methods of a singleton could be expressed as statics, it should be possible to avoid generating the singleton's class file entirely.
I was thinking that we could fake the existence of the companion object in the same way that we do with java interop. But, of course, we can't pass *those* around as instances.
What if we could, however? It would allow for a reduction in the number of classes emitted for companions, AND it would make interop more powerful.
Two for the - admittedly high - price of one :)
I was thinking that we could fake the existence of the companion object in the same way that we do with java interop. But, of course, we can't pass *those* around as instances.
What if we could, however? It would allow for a reduction in the number of classes emitted for companions, AND it would make interop more powerful.
Two for the - admittedly high - price of one :)
I'm not suggesting that this be done for ALL singleton methods, just those where there's no possibility for a namespace collision. I also don't see any problem with instance methods being visible to static methods.
On Wed, Jan 30, 2013 at 3:02 AM, Kevin Wright <kev.lee...@gmail.com> wrote:I'm not suggesting that this be done for ALL singleton methods, just those where there's no possibility for a namespace collision. I also don't see any problem with instance methods being visible to static methods.The problem isn't that they're visible to the static methods, but that they're visible to everyone else.class Foo { def f1() = 5 }object Foo { def f2() = 10 }If there is a single class Foo containing both methods, then I take it this is an instance of Foo:var x: Foo.type = FooIn scala the object Foo has no f1() method. Maybe you are thinking that we use trickery so that object Foo seems only to contain the static methods.
In that case, what will you do about this:def f(x: Any) = x match { case y: Foo => y.f1() } ; f(Foo)Again assuming I'm understanding you correctly, this is only the tip of the iceberg.
Is that not just a match failure? because Foo-the-singleton isn't an instance of Foo-the-class
--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
If we restrict the static optimisation to only those singletons that don't inherit from anything, there would never be any need to *really* pass instances around at runtime.
Sounds like a similar problem as you have with value classes. Meaning
you would need boxing in some cases but not in others. Maybe you could
even use just one wrapper class with a tag for all singleton object
types.
--
if we're talking crazy, how about having a 'java{}' construct (like C had assembly). which means the java code is compiled (with java's compiler) and added as-is to the class (not sure if this can be done...). then the user needs to know what they're doing, but maybe the static-needing crowed is already in that camp. if so, it opens up doors to other options.
Of course, we shouldn't settle for java. It would be better (except in terms of familiarity, which I understand is important) to use a language which maps directly onto bytecode, since that's the whole reason we'd be dropping below scala in the first place. Mirah maybe, or something we design for this purpose. As much as we like to call java "assembly language", it's a pretty poor assembly language.