-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Properly desugar inline given .. with ..
#14284
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
Changes from all commits
9b3cdc2
b0929f2
e26f867
5664de0
09a46f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import scala.compiletime.* | ||
|
||
trait C[A] | ||
|
||
inline given [Tup <: Tuple]: C[Tup] with | ||
val cs = summonAll[Tuple.Map[Tup, C]] // error cannot reduce inline match with |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class T | ||
|
||
transparent inline given fail1: T with // error | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
transparent inline given fail2[X]: T with // error | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
transparent inline given fail3(using DummyImplicit): T with // error | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
|
||
transparent inline given ok1: T = new T: | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
transparent inline given ok2[X]: T = new T: | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
transparent inline given ok3(using DummyImplicit): T = new T: | ||
val cs = scala.compiletime.summonAll[EmptyTuple] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class T | ||
|
||
inline given fail1: T with | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does transparent inline work / do anything useful here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It makes sure that we do not hit the previous issue where the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I mean, there are no testcases with transparent in this pr There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I completely missed the transparent. I will add some test cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Transparent is failing for the wrong reason. I do not see how transparent would be useful here because we already have the precise type. I will disallow this combination and make sure the error message is correct. |
||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
inline given fail2[X]: T with | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
inline given fail3(using DummyImplicit): T with | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
|
||
inline given ok1: T = new T: | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
inline given ok2[X]: T = new T: | ||
val cs = scala.compiletime.summonAll[EmptyTuple] | ||
inline given ok3(using DummyImplicit): T = new T: | ||
val cs = scala.compiletime.summonAll[EmptyTuple] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
trait Foo[A] { | ||
inline def foo(): Unit | ||
} | ||
|
||
inline given FooA[A]: Foo[A] with { | ||
inline def foo(): Unit = println() | ||
} | ||
def test1 = FooA.foo() | ||
|
||
inline given FooInt: Foo[Int] with { | ||
inline def foo(): Unit = println() | ||
} | ||
def test2 = FooInt.foo() |
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.
This example explains inline given but also uses inline on the method definition even though these two concepts are orthogonal, couldn't the example use a non-inline def to be kept simple?
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.
I could not come up with a useful example of inlining those givens that did not involve also inlining the method.
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.
Actually, the only reason why we did not disallow
inline given .. with ..
is for the case where it contains an inline method (as I originally intended in #14207).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.
Could the doc describe a concrete situation where it's useful then? I imagine it's needed for the method call to actually be inlined but that should be shown explicitly with an example because it's not obvious
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.
The use case of the issue at the origin of this PR was compile-time typeclass. The goal is to allow, as you said, to fully inline the method call. For example, I use it for type refinements/constraints.