You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2023-00-00-signature-polymorphic-methods.md
+33-48Lines changed: 33 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,8 @@ This blog post explains the feature and why it exists. We also delve
13
13
into how it is specified and implemented in both Scala 2 and Scala 3.
14
14
15
15
The Scala 3 implementation is new, and that's the occasion for this
16
-
blog post. Thanks to this recent work, Scala 3 users can now access
17
-
the entire Java reflection API, as of Scala 3.3.0-RC1.
16
+
blog post. Thanks to this recent work, **Scala 3 users can now access
17
+
the entire Java reflection API**, as of Scala 3.3.0.
18
18
19
19
## Should I keep reading?
20
20
@@ -40,13 +40,13 @@ or stored.
40
40
## Is signature polymorphism supported in Scala?
41
41
42
42
Yes: since Scala 2.11.5, and more fully since Scala 2.12.16. Scala 3
43
-
now has the support too, as of Scala 3.3.0-RC1.
43
+
now has the support too, as of Scala 3.3.0.
44
44
45
45
The initial Scala 2 implementation was done by [Jason Zaugg] in 2014
46
46
and refined later by [Lukas Rytz]. The latest version, with all fixes,
47
47
landed in Scala 2.12.16 (released June 2022).
48
48
49
-
Just recently, [Dale Wijnand] ported the feature to Scala 3, with the
49
+
Recently, [Dale Wijnand] ported the feature to Scala 3, with the
50
50
assistance of [Guillaume Martres] and myself, [Seth Tisue].
51
51
52
52
Jason, Lukas, Dale, and myself are members of the Scala compiler team
@@ -145,43 +145,25 @@ Great question!
145
145
146
146
Doesn't it seem puzzling that Oracle would go to so much trouble to
147
147
make Java reflection faster? If I care so much about performance,
148
-
surely I should avoid using reflection at all?
148
+
surely I should avoid using reflection entirely?
149
149
150
150
The real reason these methods need to be fast is to aid efficient
151
-
implementation of lambdas, in both Java and Scala. Additionally, they aid
152
-
efficient implementation of dynamic languages on the
153
-
JVM. `MethodHandle` was added to the JVM at the same time as
154
-
`invokeDynamic`, which serves those same two purposes.
155
-
156
-
> TODO: Is this actually accurate? I suspect it is, but I should
157
-
> dig around and confirm it, and perhaps add links.)
158
-
159
-
> TODO: I should improve the bit about "efficient implementation
160
-
> of lambdas". Adam Vandervorst wrote:
161
-
> > I'm a bit confused by the "Are these methods good for anything else" section
162
-
> > I deduce Java only uses it in "MethodHandle and VarHandle" and Scala just gained the barebones implementation.
163
-
> I replied:
164
-
> That's a good point. I will try to improve that section. In order to improve it properly, I need to dig a little deeper into how MethodHandle and VarHandle are used internally in the Java and Scala compilers.
165
-
> Jason (et al) definitely used MethodHandle when adding lambda support to the compiler back end for Scala 2.12, but I need to dig and see whether we are specifically using the signature polymorphic methods.
166
-
> I don't want to get too deep into it in the blog post itself, but I would like to expand it a bit and need to do a bit more research in order to make the expansion accurate.
167
-
168
-
> TODO: I might rethink how I'm presenting the issue of speed here. As I wrote to
169
-
> Adam:
170
-
> that's kind of what I was getting at with the " If I care so much about performance, surely I should avoid using reflection at all?"
171
-
> if I understand correctly, if you aren't a language implementer, then boxing overhead in reflection is probably the least of your worries
172
-
> but the methods are signature polymorphic regardless
173
-
> so we need the compiler support in Scala in order for the methods to even be callable at all by users who don't care about speed
174
-
> it's a bit tricky to convey this without making the post overlong
151
+
implementation of dynamic languages on the JVM. `MethodHandle` was
152
+
added to the JVM at the same time as `invokeDynamic`, as part of
153
+
[JSR-292](), which aimed to support efficient implementation of JRuby
154
+
and other alternative JVM languages. (`invokeDynamic` is additionally
155
+
used for implementing lambdas; see [this writeup on Stack Overflow]().)
0 commit comments