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.
Part of the fix for scala#15413 Part of the fix for scala#16983
- Loading branch information
1 parent
847eccc
commit eaf0804
Showing
13 changed files
with
218 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package scala.annotation | ||
|
||
/** TODO | ||
*/ | ||
@experimental | ||
final class inlineAccessible extends StaticAnnotation |
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 @@ | ||
package foo | ||
|
||
import scala.annotation.inlineAccessible | ||
|
||
@inlineAccessible type A // error | ||
@inlineAccessible object B // error // TODO support? | ||
@inlineAccessible class C // error |
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,8 @@ | ||
import scala.quoted.* | ||
import scala.annotation.inlineAccessible | ||
|
||
class Macro: | ||
inline def foo = ${ Macro.fooImpl } | ||
|
||
object Macro: | ||
@inlineAccessible 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,6 @@ | ||
import scala.quoted.* | ||
import scala.annotation.inlineAccessible | ||
|
||
inline def foo = ${ fooImpl } | ||
|
||
@inlineAccessible 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,61 @@ | ||
// package foo | ||
|
||
import scala.annotation.inlineAccessible | ||
|
||
class Foo(@inlineAccessible param: Int): | ||
@inlineAccessible | ||
private val privateVal: Int = 2 | ||
|
||
@inlineAccessible | ||
protected val protectedVal: Int = 2 | ||
|
||
@inlineAccessible | ||
private[foo] def packagePrivateVal: Int = 2 | ||
inline def foo: Int = param + privateVal + protectedVal + packagePrivateVal | ||
|
||
class Bar() extends Foo(3): | ||
override protected val protectedVal: Int = 2 | ||
|
||
override private[foo] def packagePrivateVal: Int = 2 | ||
|
||
inline def bar: Int = protectedVal + packagePrivateVal // TODO reuse accessor in Foo | ||
|
||
class Baz() extends Foo(4): | ||
@inlineAccessible // TODO warn? : does not need an accessor and it overrides a field that has an accessor. | ||
override protected val protectedVal: Int = 2 | ||
|
||
@inlineAccessible | ||
override private[foo] def packagePrivateVal: Int = 2 | ||
|
||
inline def baz: Int = protectedVal + packagePrivateVal | ||
|
||
|
||
class Qux() extends Foo(5): | ||
inline def qux: Int = protectedVal + packagePrivateVal | ||
|
||
def test = | ||
@inlineAccessible // noop | ||
val a = 5 | ||
|
||
Foo(3).foo | ||
Bar().bar | ||
Baz().baz | ||
Qux().qux | ||
|
||
|
||
package inlines { | ||
// Case that needed to be converted with MakeInlineablePassing | ||
class C[T](x: T) { | ||
@inlineAccessible private[inlines] def next[U](y: U): (T, U) = (x, y) | ||
} | ||
class TestPassing { | ||
inline def foo[A](x: A): (A, Int) = { | ||
val c = new C[A](x) | ||
c.next(1) | ||
} | ||
inline def bar[A](x: A): (A, String) = { | ||
val c = new C[A](x) | ||
c.next("") | ||
} | ||
} | ||
} |
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