Skip to content

Commit 1516b06

Browse files
Merge pull request #8756 from dotty-staging/use-transparent-inline-in-the-library
Use transparent inline in the library
2 parents c560211 + 417c39d commit 1516b06

File tree

28 files changed

+43
-41
lines changed

28 files changed

+43
-41
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,6 +3288,7 @@ object Parsers {
32883288
leadingVparamss ::: rparamss
32893289
var tpt = fromWithinReturnType {
32903290
if in.token == SUBTYPE && mods.is(Inline) && AllowOldWhiteboxSyntax then
3291+
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
32913292
in.nextToken()
32923293
mods1 = addMod(mods1, Mod.Transparent())
32933294
toplevelTyp()
@@ -3557,6 +3558,7 @@ object Parsers {
35573558
mods1 |= Final
35583559
DefDef(name, tparams, vparamss, tpt, subExpr())
35593560
if in.token == USCORE && AllowOldWhiteboxSyntax then
3561+
deprecationWarning("`<:` return type will no longer be supported. Use transparent modifier instead.")
35603562
if !mods.is(Inline) then
35613563
syntaxError("`_ <:` is only allowed for given with `inline` modifier")
35623564
in.nextToken()

library/src/dotty/DottyPredef.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object DottyPredef {
88
assertFail(message)
99
}
1010

11-
inline final def assert(inline assertion: Boolean) <: Unit = {
11+
transparent inline final def assert(inline assertion: Boolean): Unit = {
1212
if (!assertion)
1313
assertFail()
1414
}

library/src/scala/compiletime/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ package object compiletime {
5252
*
5353
* the returned value would be `2`.
5454
*/
55-
inline def summonFrom[T](f: Nothing => T) <: T = ???
55+
transparent inline def summonFrom[T](f: Nothing => T): T = ???
5656

5757

5858
/** Summon a given value of type `T`. Usually, the argument is not passed explicitly.
@@ -61,7 +61,7 @@ package object compiletime {
6161
* @tparam T the type of the value to be summoned
6262
* @return the given value typed as the provided type parameter
6363
*/
64-
inline def summonInline[T] <: T = summonFrom {
64+
transparent inline def summonInline[T]: T = summonFrom {
6565
case t: T => t
6666
}
6767

tests/invalid/run/typelevel-patmat.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ object Test extends App {
4545
inline val i2 = toInt(y2)
4646
val j2: 2 = i2
4747

48-
inline def concat(xs: HList, ys: HList) <: HList = inline xs match {
48+
transparent inline def concat(xs: HList, ys: HList): HList = inline xs match {
4949
case HNil => ys
5050
case HCons(x, xs1) => HCons(x, concat(xs1, ys))
5151
}
@@ -68,7 +68,7 @@ object Test extends App {
6868
val r6 = concat(HCons(1, HCons("a", HNil)), HCons(true, HCons(1.0, HNil)))
6969
val c6: HCons[Int, HCons[String, HCons[Boolean, HCons[Double, HNil]]]] = r6
7070

71-
inline def nth(xs: HList, n: Int) <: Any = inline xs match {
71+
transparent inline def nth(xs: HList, n: Int): Any = inline xs match {
7272
case HCons(x, _) if n == 0 => x
7373
case HCons(_, xs1) if n > 0 => nth(xs1, n - 1)
7474
}

tests/invalid/run/typelevel1.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ trait HList {
44
def head: Any
55
def tail: HList
66

7-
inline def isEmpty <: Boolean = length == 0
7+
transparent inline def isEmpty: Boolean = length == 0
88
}
99

1010
case object HNil extends HList {
11-
inline override def length <: Int = 0
11+
transparent inline override def length: Int = 0
1212
def head: Nothing = ???
1313
def tail: Nothing = ???
1414
}
1515

1616
case class :: [H, T <: HList] (hd: H, tl: T) extends HList {
17-
inline override def length <: Int = 1 + tl.length
17+
transparent inline override def length: Int = 1 + tl.length
1818
inline def head: H = this.hd
1919
inline def tail: T = this.tl
2020
}
@@ -32,7 +32,7 @@ object Test extends App {
3232

3333
// Does not work since it infers `Any` as a type argument for `::`
3434
// and we cannot undo that without a typing from untyped.
35-
inline def concat[T1, T2](xs: HList, ys: HList) <: HList =
35+
transparent inline def concat[T1, T2](xs: HList, ys: HList): HList =
3636
inline if xs.isEmpty then ys
3737
else new ::(xs.head, concat(xs.tail, ys))
3838

tests/neg-macros/quote-whitebox/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22

33
object Macros {
4-
inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) }
4+
transparent inline def defaultOf(inline str: String): Any = ${ defaultOfImpl('str) }
55
def defaultOfImpl(str: Expr[String]) (using QuoteContext): Expr[Any] = str.unliftOrError match {
66
case "int" => '{1}
77
case "string" => '{"a"}

tests/neg/specializing-inline.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object Test {
44
val z = h(true)
55
val zc: Int = z // error
66

7-
inline def g <: Any = 1
7+
transparent inline def g: Any = 1
88
val y = g
99
val yc: Int = y // OK
1010

tests/pending/pos/summonFrom.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ object summonFroms {
44
object invariant {
55
case class Box[T](value: T)
66
implicit val box: Box[Int] = Box(0)
7-
inline def unbox <: Any = summonInline[Box[t]].value
7+
transparent inline def unbox: Any = summonInline[Box[t]].value
88
val i: Int = unbox
99
val i2 = unbox
1010
val i3: Int = i2
@@ -13,7 +13,7 @@ object summonFroms {
1313
object covariant {
1414
case class Box[+T](value: T)
1515
implicit val box: Box[Int] = Box(0)
16-
inline def unbox <: Any = summonInline[Box[t]].value
16+
transparent inline def unbox: Any = summonInline[Box[t]].value
1717
val i: Int = unbox
1818
val i2 = unbox
1919
val i3: Int = i2
@@ -22,7 +22,7 @@ object summonFroms {
2222
object contravariant {
2323
case class TrashCan[-T](trash: T => Unit)
2424
implicit val trashCan: TrashCan[Int] = TrashCan { i => ; }
25-
inline def trash <: Nothing => Unit = summonInline[TrashCan[t]].trash
25+
transparent inline def trash: Nothing => Unit = summonInline[TrashCan[t]].trash
2626
val t1: Int => Unit = trash
2727
val t2 = trash
2828
val t3: Int => Unit = t2

tests/pos-macros/quote-whitebox-2/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.quoted._
33

44
object Macro {
55

6-
inline def charOrString(inline str: String) <: Any = ${ impl('str) }
6+
transparent inline def charOrString(inline str: String): Any = ${ impl('str) }
77

88
def impl(strExpr: Expr[String]) (using QuoteContext)=
99
val str = strExpr.unliftOrError

tests/pos/given-pattern.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
class Test {
44
import scala.collection.immutable.{TreeSet, HashSet}
55

6-
inline def trySummon[S, T](f: PartialFunction[S, T]) <: T = ???
6+
transparent inline def trySummon[S, T](f: PartialFunction[S, T]): T = ???
77

88
inline def setFor[T]: Set[T] = trySummon {
99
case given ord: Ordering[T] => new TreeSet[T]

tests/pos/i4006.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
class Foo {
2-
inline def foo <: Int = try { 1 } finally println("Hello")
2+
transparent inline def foo: Int = try { 1 } finally println("Hello")
33
foo
44
}

tests/pos/i5574.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import scala.compiletime._
33
object i5574 {
44
class Box[F[_]]
55

6-
inline def foo[T] <: Any =
6+
transparent inline def foo[T]: Any =
77
inline erasedValue[T] match {
88
case _: Box[f] =>
99
type t = f

tests/pos/i6213.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Test {
22
class C { type T }
3-
inline def foo[U] <: Any = (??? : C { type T = U })
3+
transparent inline def foo[U]: Any = (??? : C { type T = U })
44

55
foo[Int]
66
}

tests/pos/i7078.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
trait A
22
class B extends A
33

4-
inline given tc as _ <: A = B()
4+
transparent inline given tc as A = B()
55

66
val x: B = summon[A]
77

tests/pos/i7358.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package test
33
import scala.quoted._
44
import scala.compiletime._
55

6-
inline def summonT[Tp <: Tuple](using QuoteContext) <: Tuple = inline erasedValue[Tp] match {
6+
transparent inline def summonT[Tp <: Tuple](using QuoteContext): Tuple = inline erasedValue[Tp] match {
77
case _ : Unit => ()
88
case _ : (hd *: tl) => {
99
type H = hd

tests/pos/inline-caseclass.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ case class S[N <: Nat](n: N) extends Nat
55
object Test {
66
type Z = Z.type
77

8-
inline def add(x: Nat, y: Int) <: Int = inline x match {
8+
transparent inline def add(x: Nat, y: Int): Int = inline x match {
99
case Z => y
1010
case S(x1) => add(x1, y) + 1
1111
}

tests/pos/inline-constfold.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
object Test {
2-
inline def not(x: Boolean) <: Boolean = {
2+
transparent inline def not(x: Boolean): Boolean = {
33
!x
44
}
55

66
final val a = not(true)
77
val b: false = a
88

9-
inline def add(x: Int, y: Int) <: Int = {
9+
transparent inline def add(x: Int, y: Int): Int = {
1010
x + y
1111
}
1212

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object Utils {
22
class Box[T]
3-
inline def foo[T](t: T) <: Any = inline t match {
3+
transparent inline def foo[T](t: T): Any = inline t match {
44
case _: Box[a] => scala.compiletime.constValue[a]
55
}
66
}

tests/pos/reference/compile-time.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Test:
77
case object Zero extends Nat
88
case class Succ[N <: Nat](n: N) extends Nat
99

10-
inline def toIntC[N] <: Int =
10+
transparent inline def toIntC[N]: Int =
1111
inline constValue[N] match
1212
case 0 => 0
1313
case _: S[n1] => 1 + toIntC[n1]
@@ -31,10 +31,10 @@ class Test:
3131
val dBoolean: Some[Boolean] = defaultValue[Boolean]
3232
val dAny: None.type = defaultValue[Any]
3333

34-
inline def toIntT[N <: Nat] <: Int = inline scala.compiletime.erasedValue[N] match
34+
transparent inline def toIntT[N <: Nat]: Int = inline scala.compiletime.erasedValue[N] match
3535
case _: Zero.type => 0
3636
case _: Succ[n] => toIntT[n] + 1
3737

38-
inline def summonFrom(f: Nothing => Any) <: Any = ???
38+
transparent inline def summonFrom(f: Nothing => Any): Any = ???
3939

4040
final val two = toIntT[Succ[Succ[Zero.type]]]

tests/pos/reference/inline-match.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package inlinematch
22

33
class Test {
44

5-
inline def g(x: Any) <: Any = inline x match {
5+
transparent inline def g(x: Any): Any = inline x match {
66
case x: String => (x, x) // Tuple2[String, String](x, x)
77
case x: Double => x
88
}
@@ -14,7 +14,7 @@ class Test {
1414
case object Zero extends Nat
1515
case class Succ[N <: Nat](n: N) extends Nat
1616

17-
inline def toInt(n: Nat) <: Int = inline n match {
17+
transparent inline def toInt(n: Nat): Int = inline n match {
1818
case Zero => 0
1919
case Succ(n1) => toInt(n1) + 1
2020
}

tests/pos/reference/inline-specializing.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ object Test{
66
def meth() = true
77
}
88

9-
inline def choose(b: Boolean) <: A = {
9+
transparent inline def choose(b: Boolean): A = {
1010
if (b) new A()
1111
else new B()
1212
}

tests/pos/typelevel0.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@ trait HList {
44
def head: Any
55
def tail: HList
66

7-
inline def isEmpty <: Boolean = length == 0
7+
transparent inline def isEmpty: Boolean = length == 0
88
}
99

1010
case object HNil extends HList {
11-
inline override def length <: Int = 0
11+
transparent inline override def length: Int = 0
1212
def head: Nothing = ???
1313
def tail: Nothing = ???
1414
}
1515

1616
case class :: [+H, +T <: HList] (hd: H, tl: T) extends HList {
17-
inline override def length <: Int = 1 + tl.length
17+
transparent inline override def length: Int = 1 + tl.length
1818
def head: H = this.hd
1919
def tail: T = this.tl
2020
}

tests/run-custom-args/companion-loading.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ implicit object FooAssoc extends Assoc[Foo] {
2121

2222
import compiletime.summonFrom
2323

24-
inline def link[T] <: Any =
24+
transparent inline def link[T]: Any =
2525
summonFrom {
2626
case _: Link[T, s] =>
2727
summonFrom {

tests/run-macros/i7898/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Main {
1212
}
1313
}
1414

15-
inline def myMacro(body: => Any) <: Any = ${
15+
transparent inline def myMacro(body: => Any): Any = ${
1616
myMacroImpl('body)
1717
}
1818
}

tests/run-macros/quote-whitebox/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import scala.quoted._
22

33
object Macros {
4-
inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) }
4+
transparent inline def defaultOf(inline str: String): Any = ${ defaultOfImpl('str) }
55
def defaultOfImpl(str: Expr[String]) (using QuoteContext): Expr[Any] = str.unliftOrError match {
66
case "int" => '{1}
77
case "string" => '{"a"}

tests/run-macros/refined-selectable-macro/Macro_1.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import scala.quoted._
33
object Macro {
44

55
trait SelectableRecord extends Selectable {
6-
inline def toTuple <: Tuple = ${ toTupleImpl('this)}
6+
transparent inline def toTuple: Tuple = ${ toTupleImpl('this)}
77
}
88

99
trait SelectableRecordCompanion[T] {
1010
protected def fromUntypedTuple(elems: (String, Any)*): T
11-
inline def fromTuple[T <: Tuple](inline s: T) <: Any = ${ fromTupleImpl('s, '{ (x: Array[(String, Any)]) => fromUntypedTuple(x: _*) } ) }
11+
transparent inline def fromTuple[T <: Tuple](inline s: T): Any = ${ fromTupleImpl('s, '{ (x: Array[(String, Any)]) => fromUntypedTuple(x: _*) } ) }
1212
}
1313

1414
private def toTupleImpl(s: Expr[Selectable])(using qctx:QuoteContext) : Expr[Tuple] = {

tests/run-staging/i3876-d.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ object Test {
1313
println(withQuoteContext(Expr.betaReduce(f4)(x).show))
1414
}
1515

16-
inline def inlineLambda <: Int => Int = x => x + x
16+
transparent inline def inlineLambda: Int => Int = x => x + x
1717
}

tests/run-staging/i3876-e.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ object Test {
1313
println(withQuoteContext(Expr.betaReduce(f4)(x).show))
1414
}
1515

16-
inline def inlineLambda <: Int => Int = x => x + x
16+
transparent inline def inlineLambda: Int => Int = x => x + x
1717
}

0 commit comments

Comments
 (0)