forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generate static inline accessors module
If a class needs inline accessors that would be added top-level or if the accessor is to a static member, we place it in the top-level class as a java static method. If the accessor location in the new scheme is not the same as the previous location, we also generate the old accessor for backward binary compatibility but do not use it. Fixes scala#13215 Fixes scala#15413
- Loading branch information
1 parent
72df9cd
commit 7542e95
Showing
34 changed files
with
324 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import scala.quoted.* | ||
|
||
class Macro: | ||
inline def foo = ${ Macro.fooImpl } | ||
|
||
object Macro: | ||
private def fooImpl(using Quotes) = '{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test = | ||
new Macro().foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import scala.quoted.* | ||
|
||
inline def foo = ${ fooImpl } | ||
|
||
private def fooImpl(using Quotes) = '{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def test = foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import scala.quoted.* | ||
|
||
class Macro: | ||
inline def foo = ${ Macro.fooImpl } | ||
|
||
object Macro: | ||
private def fooImpl(using Quotes) = '{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test = | ||
new Macro().foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import scala.quoted.* | ||
|
||
inline def foo = ${ fooImpl } | ||
|
||
private def fooImpl(using Quotes) = '{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def test = foo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package myMacro | ||
|
||
import scala.quoted.* | ||
|
||
class Macro: | ||
inline def foo = ${ Foo.impl } | ||
inline def bar = ${ Bar.impl } | ||
inline def baz = ${ foo.Foo.impl } | ||
|
||
object Foo: | ||
private[myMacro] def impl(using Quotes) = '{} | ||
|
||
object Bar: | ||
private[myMacro] def impl(using Quotes) = '{1} | ||
|
||
package foo: | ||
object Foo: | ||
private[myMacro] def impl(using Quotes) = '{"abc"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import myMacro.Macro | ||
|
||
def test(m: Macro) = | ||
m.foo | ||
m.bar | ||
m.baz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package foo | ||
|
||
trait Bar: | ||
inline def baz = Baz | ||
|
||
private[foo] object Baz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package foo | ||
|
||
trait Bar: | ||
inline def baz = Baz | ||
|
||
private[foo] object Baz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// We first compile A using 3.1 to generate the old accessors | ||
// Then we compile this file to link against the old accessors | ||
// Finally we recompile A using the current compiler to generate a version | ||
// of A that contains the new accessors (and the old for backwards compat) | ||
|
||
@main def Test = | ||
val bar: foo.Bar = new foo.Bar{} | ||
bar.baz // test that old accessor links in 3.4+ | ||
|
||
// Check that both accessors exist in the bytecode | ||
val inlineAccessors = | ||
java.lang.Class.forName("foo.Bar").getMethods() | ||
.filter(_.getName().contains("inline")) | ||
.filter(x => (x.getModifiers() & java.lang.reflect.Modifier.STATIC) == 0) | ||
.map(_.getName()) | ||
.toList | ||
val staticInlineAccessors = | ||
java.lang.Class.forName("foo.Bar").getMethods() | ||
.filter(_.getName().contains("inline")) | ||
.filter(x => (x.getModifiers() & java.lang.reflect.Modifier.STATIC) != 0) | ||
.map(_.getName()) | ||
.toList | ||
|
||
println("3.0-3.3 inline accessor: " + inlineAccessors) | ||
println("3.4+ inline accessor: " + staticInlineAccessors) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
3.0-3.3 inline accessor: List(Macro$$inline$fooImpl) | ||
3.4+ inline accessor: List(Macro$$inline$static$fooImpl) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import scala.quoted.* | ||
|
||
class Macro: | ||
inline def foo = /*${*/ Macro.fooImpl /*}*/ | ||
|
||
object Macro: | ||
private def fooImpl/*(using Quotes)*/ = {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import scala.quoted.* | ||
|
||
class Macro: | ||
inline def foo = /*${*/ Macro.fooImpl /*}*/ | ||
|
||
object Macro: | ||
private def fooImpl/*(using Quotes)*/ = {} |
Oops, something went wrong.