Skip to content

Commit 999d1cb

Browse files
Merge pull request #5109 from dotty-staging/rewrite-to-inlined
Back to the future: `rewrite` to `inline`
2 parents 9bfaf2b + e9fe005 commit 999d1cb

File tree

262 files changed

+781
-817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

262 files changed

+781
-817
lines changed

bench/tests/power-macro/PowerMacro.scala

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

33
object PowerMacro {
44

5-
rewrite def power(transparent n: Long, x: Double) = ~powerCode(n, '(x))
5+
inline def power(inline n: Long, x: Double) = ~powerCode(n, '(x))
66

77
def powerCode(n: Long, x: Expr[Double]): Expr[Double] =
88
if (n == 0) '(1.0)

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,11 +464,11 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
464464
* Strictly speaking we can't replace `O.x` with `42`. But this would make
465465
* most expressions non-constant. Maybe we can change the spec to accept this
466466
* kind of eliding behavior. Or else enforce true purity in the compiler.
467-
* The choice will be affected by what we will do with `transparent` and with
467+
* The choice will be affected by what we will do with `inline` and with
468468
* Singleton type bounds (see SIP 23). Presumably
469469
*
470470
* object O1 { val x: Singleton = 42; println("43") }
471-
* object O2 { transparent val x = 42; println("43") }
471+
* object O2 { inline val x = 42; println("43") }
472472
*
473473
* should behave differently.
474474
*
@@ -478,8 +478,8 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
478478
*
479479
* O2.x = 42
480480
*
481-
* Revisit this issue once we have standardized on `transparent`. Then we can demand
482-
* purity of the prefix unless the selection goes to a transparent val.
481+
* Revisit this issue once we have standardized on `inline`. Then we can demand
482+
* purity of the prefix unless the selection goes to a inline val.
483483
*
484484
* Note: This method should be applied to all term tree nodes that are not literals,
485485
* that can be idempotent, and that can have constant types. So far, only nodes

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -497,9 +497,9 @@ object Trees {
497497
extends TermTree[T] {
498498
type ThisTree[-T >: Untyped] = If[T]
499499
}
500-
class RewriteIf[T >: Untyped] private[ast] (cond: Tree[T], thenp: Tree[T], elsep: Tree[T])
500+
class InlineIf[T >: Untyped] private[ast] (cond: Tree[T], thenp: Tree[T], elsep: Tree[T])
501501
extends If(cond, thenp, elsep) {
502-
override def toString = s"RewriteIf($cond, $thenp, $elsep)"
502+
override def toString = s"InlineIf($cond, $thenp, $elsep)"
503503
}
504504

505505
/** A closure with an environment and a reference to a method.
@@ -521,9 +521,9 @@ object Trees {
521521
extends TermTree[T] {
522522
type ThisTree[-T >: Untyped] = Match[T]
523523
}
524-
class RewriteMatch[T >: Untyped] private[ast] (selector: Tree[T], cases: List[CaseDef[T]])
524+
class InlineMatch[T >: Untyped] private[ast] (selector: Tree[T], cases: List[CaseDef[T]])
525525
extends Match(selector, cases) {
526-
override def toString = s"RewriteMatch($selector, $cases)"
526+
override def toString = s"InlineMatch($selector, $cases)"
527527
}
528528

529529
/** case pat if guard => body; only appears as child of a Match */
@@ -904,10 +904,10 @@ object Trees {
904904
type Assign = Trees.Assign[T]
905905
type Block = Trees.Block[T]
906906
type If = Trees.If[T]
907-
type RewriteIf = Trees.RewriteIf[T]
907+
type InlineIf = Trees.InlineIf[T]
908908
type Closure = Trees.Closure[T]
909909
type Match = Trees.Match[T]
910-
type RewriteMatch = Trees.RewriteMatch[T]
910+
type InlineMatch = Trees.InlineMatch[T]
911911
type CaseDef = Trees.CaseDef[T]
912912
type Labeled = Trees.Labeled[T]
913913
type Return = Trees.Return[T]
@@ -1038,9 +1038,9 @@ object Trees {
10381038
case _ => finalize(tree, untpd.Block(stats, expr))
10391039
}
10401040
def If(tree: Tree)(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = tree match {
1041-
case tree: RewriteIf =>
1041+
case tree: InlineIf =>
10421042
if ((cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep)) tree
1043-
else finalize(tree, untpd.RewriteIf(cond, thenp, elsep))
1043+
else finalize(tree, untpd.InlineIf(cond, thenp, elsep))
10441044
case tree: If if (cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep) => tree
10451045
case _ => finalize(tree, untpd.If(cond, thenp, elsep))
10461046
}
@@ -1049,9 +1049,9 @@ object Trees {
10491049
case _ => finalize(tree, untpd.Closure(env, meth, tpt))
10501050
}
10511051
def Match(tree: Tree)(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = tree match {
1052-
case tree: RewriteMatch =>
1052+
case tree: InlineMatch =>
10531053
if ((selector eq tree.selector) && (cases eq tree.cases)) tree
1054-
else finalize(tree, untpd.RewriteMatch(selector, cases))
1054+
else finalize(tree, untpd.InlineMatch(selector, cases))
10551055
case tree: Match if (selector eq tree.selector) && (cases eq tree.cases) => tree
10561056
case _ => finalize(tree, untpd.Match(selector, cases))
10571057
}

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
132132

133133
case class Lazy() extends Mod(Flags.Lazy)
134134

135-
case class Rewrite() extends Mod(Flags.Rewrite)
136-
137-
case class Transparent() extends Mod(Flags.Transparent)
135+
case class Inline() extends Mod(Flags.Inline)
138136

139137
case class Enum() extends Mod(Flags.Enum)
140138
}
@@ -275,10 +273,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
275273
def Assign(lhs: Tree, rhs: Tree): Assign = new Assign(lhs, rhs)
276274
def Block(stats: List[Tree], expr: Tree): Block = new Block(stats, expr)
277275
def If(cond: Tree, thenp: Tree, elsep: Tree): If = new If(cond, thenp, elsep)
278-
def RewriteIf(cond: Tree, thenp: Tree, elsep: Tree): If = new RewriteIf(cond, thenp, elsep)
276+
def InlineIf(cond: Tree, thenp: Tree, elsep: Tree): If = new InlineIf(cond, thenp, elsep)
279277
def Closure(env: List[Tree], meth: Tree, tpt: Tree): Closure = new Closure(env, meth, tpt)
280278
def Match(selector: Tree, cases: List[CaseDef]): Match = new Match(selector, cases)
281-
def RewriteMatch(selector: Tree, cases: List[CaseDef]): Match = new RewriteMatch(selector, cases)
279+
def InlineMatch(selector: Tree, cases: List[CaseDef]): Match = new InlineMatch(selector, cases)
282280
def CaseDef(pat: Tree, guard: Tree, body: Tree): CaseDef = new CaseDef(pat, guard, body)
283281
def Labeled(bind: Bind, expr: Tree): Labeled = new Labeled(bind, expr)
284282
def Return(expr: Tree, from: Tree): Return = new Return(expr, from)

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ScalaSettings extends Settings.SettingGroup {
4343
val pageWidth = IntSetting("-pagewidth", "Set page width", 80)
4444
val strict = BooleanSetting("-strict", "Use strict type rules, which means some formerly legal code does not typecheck anymore.")
4545
val language = MultiStringSetting("-language", "feature", "Enable one or more language features.")
46-
val `rewrite` = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
46+
val rewrite = OptionSetting[Rewrites]("-rewrite", "When used in conjunction with -language:Scala2 rewrites sources to migrate to new syntax")
4747
val silentWarnings = BooleanSetting("-nowarn", "Silence all warnings.")
4848
val fromTasty = BooleanSetting("-from-tasty", "Compile classes from tasty in classpath. The arguments are used as class names.")
4949

compiler/src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ object Annotations {
5757
}
5858

5959
/** An annotation indicating the body of a right-hand side,
60-
* typically of a rewrite or transparent method. Treated specially in
60+
* typically of an inline method. Treated specially in
6161
* pickling/unpickling and TypeTreeMaps
6262
*/
6363
abstract class BodyAnnotation extends Annotation {

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -764,8 +764,8 @@ class Definitions {
764764
def ImplicitNotFoundAnnot(implicit ctx: Context) = ImplicitNotFoundAnnotType.symbol.asClass
765765
lazy val ForceInlineAnnotType = ctx.requiredClassRef("scala.forceInline")
766766
def ForceInlineAnnot(implicit ctx: Context) = ForceInlineAnnotType.symbol.asClass
767-
lazy val TransparentParamAnnotType = ctx.requiredClassRef("scala.annotation.internal.TransparentParam")
768-
def TransparentParamAnnot(implicit ctx: Context) = TransparentParamAnnotType.symbol.asClass
767+
lazy val InlineParamAnnotType = ctx.requiredClassRef("scala.annotation.internal.InlineParam")
768+
def InlineParamAnnot(implicit ctx: Context) = InlineParamAnnotType.symbol.asClass
769769
lazy val InvariantBetweenAnnotType = ctx.requiredClassRef("scala.annotation.internal.InvariantBetween")
770770
def InvariantBetweenAnnot(implicit ctx: Context) = InvariantBetweenAnnotType.symbol.asClass
771771
lazy val MigrationAnnotType = ctx.requiredClassRef("scala.annotation.migration")

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,8 @@ object Flags {
283283
*/
284284
final val Synthetic = commonFlag(18, "<synthetic>")
285285

286-
/** Labelled with `rewrite` modifier */
287-
final val Rewrite = commonFlag(19, "rewrite")
286+
/** Labelled with `inline` modifier */
287+
final val Inline = commonFlag(19, "inline")
288288

289289
/** A covariant type variable / an outer accessor */
290290
final val CovariantOrOuter = commonFlag(20, "")
@@ -329,9 +329,6 @@ object Flags {
329329
/** A method that has default params */
330330
final val DefaultParameterized = termFlag(27, "<defaultparam>")
331331

332-
/** Labelled with `transparent` modifier */
333-
final val Transparent = commonFlag(29, "transparent")
334-
335332
/** Symbol is defined by a Java class */
336333
final val JavaDefined = commonFlag(30, "<java>")
337334

@@ -436,7 +433,7 @@ object Flags {
436433

437434
/** Flags representing source modifiers */
438435
final val SourceModifierFlags =
439-
commonFlags(Private, Protected, Abstract, Final, Rewrite | Transparent,
436+
commonFlags(Private, Protected, Abstract, Final, Inline,
440437
Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Erased)
441438

442439
/** Flags representing modifiers that can appear in trees */
@@ -457,7 +454,7 @@ object Flags {
457454
Scala2ExistentialCommon | Mutable.toCommonFlags | Touched | JavaStatic |
458455
CovariantOrOuter | ContravariantOrLabel | CaseAccessor.toCommonFlags |
459456
NonMember | ImplicitCommon | Permanent | Synthetic |
460-
SuperAccessorOrScala2x | Rewrite | Transparent
457+
SuperAccessorOrScala2x | Inline
461458

462459
/** Flags that are not (re)set when completing the denotation, or, if symbol is
463460
* a top-level class or object, when completing the denotation once the class
@@ -551,26 +548,23 @@ object Flags {
551548
/** Assumed to be pure */
552549
final val StableOrErased = Stable | Erased
553550

554-
/** Labeled `private`, `final`, `rewrite` or `transparent` */
555-
final val EffectivelyFinal = Private | Final | Rewrite | Transparent
551+
/** Labeled `private`, `final`, or `inline` */
552+
final val EffectivelyFinal = Private | Final | Inline
556553

557554
/** A private method */
558555
final val PrivateMethod = allOf(Private, Method)
559556

560557
/** A private accessor */
561558
final val PrivateAccessor = allOf(Private, Accessor)
562559

563-
/** A transparent method */
564-
final val TransparentMethod = allOf(Transparent, Method)
565-
566-
/** A rewrite method */
567-
final val RewriteMethod = allOf(Rewrite, Method)
560+
/** An inline method */
561+
final val InlineMethod = allOf(Inline, Method)
568562

569-
/** An implicit rewrite method */
570-
final val ImplicitRewriteMethod = allOf(Rewrite, Implicit, Method)
563+
/** An implicit inline method */
564+
final val ImplicitInlineMethod = allOf(Inline, Implicit, Method)
571565

572-
/** A transparent parameter */
573-
final val TransparentParam = allOf(Transparent, Param)
566+
/** An inline parameter */
567+
final val InlineParam = allOf(Inline, Param)
574568

575569
/** An enum case */
576570
final val EnumCase = allOf(Enum, Case)
@@ -596,8 +590,8 @@ object Flags {
596590
/** A deferred type member or parameter (these don't have right hand sides) */
597591
final val DeferredOrTypeParam = Deferred | TypeParam
598592

599-
/** value that's final or transparent */
600-
final val FinalOrTransparent = Final | Transparent
593+
/** value that's final or inline */
594+
final val FinalOrInline = Final | Inline
601595

602596
/** A covariant type parameter instance */
603597
final val LocalCovariant = allOf(Local, Covariant)

compiler/src/dotty/tools/dotc/core/Mode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ object Mode {
9595
/** We are in the IDE */
9696
val Interactive = newMode(20, "Interactive")
9797

98-
/** We are typing the body of a transparent or rewrite method */
98+
/** We are typing the body of an inline method */
9999
val InlineableBody = newMode(21, "InlineableBody")
100100

101101
/** Read comments from definitions when unpickling from TASTY */

compiler/src/dotty/tools/dotc/core/NameKinds.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ object NameKinds {
294294
val SuperArgName = new UniqueNameKind("$superArg$")
295295
val DocArtifactName = new UniqueNameKind("$doc")
296296
val UniqueInlineName = new UniqueNameKind("$i")
297-
val RewriteScrutineeName = new UniqueNameKind("$scrutinee")
298-
val RewriteBinderName = new UniqueNameKind("$elem")
297+
val InlineScrutineeName = new UniqueNameKind("$scrutinee")
298+
val InlineBinderName = new UniqueNameKind("$elem")
299299

300300
/** A kind of unique extension methods; Unlike other unique names, these can be
301301
* unmangled.

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -779,17 +779,10 @@ object SymDenotations {
779779

780780
def isSkolem: Boolean = name == nme.SKOLEM
781781

782-
def isTransparentMethod(implicit ctx: Context): Boolean =
783-
is(TransparentMethod, butNot = AccessorOrSynthetic)
782+
def isInlineMethod(implicit ctx: Context): Boolean =
783+
is(InlineMethod, butNot = AccessorOrSynthetic)
784784

785-
def isRewriteMethod(implicit ctx: Context): Boolean =
786-
is(RewriteMethod, butNot = AccessorOrSynthetic)
787-
788-
/** A transparent or rewrite method */
789-
def isInlineable(implicit ctx: Context): Boolean =
790-
is(TransparentMethod) || is(RewriteMethod)
791-
792-
/** An erased value or a rewrite method, excluding @forceInline annotated methods.
785+
/** An erased value or an inline method, excluding @forceInline annotated methods.
793786
* The latter have to be kept around to get to parity with Scala.
794787
* This is necessary at least until we have full bootstrap. Right now
795788
* dotty-bootstrapped involves running the Dotty compiler compiled with Scala 2 with
@@ -799,7 +792,7 @@ object SymDenotations {
799792
*/
800793
def isEffectivelyErased(implicit ctx: Context): Boolean =
801794
is(Erased) ||
802-
isRewriteMethod && unforcedAnnotation(defn.ForceInlineAnnot).isEmpty
795+
isInlineMethod && unforcedAnnotation(defn.ForceInlineAnnot).isEmpty
803796

804797
/** ()T and => T types should be treated as equivalent for this symbol.
805798
* Note: For the moment, we treat Scala-2 compiled symbols as loose matching,

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,8 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
279279
violations.toList
280280
}
281281

282-
/** Are we in a rewrite method body? */
283-
def inRewriteMethod = owner.ownersIterator.exists(_.isRewriteMethod)
282+
/** Are we in an inline method body? */
283+
def inInlineMethod = owner.ownersIterator.exists(_.isInlineMethod)
284284

285285
/** Is `feature` enabled in class `owner`?
286286
* This is the case if one of the following two alternatives holds:

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3031,18 +3031,18 @@ object Types {
30313031
abstract class MethodTypeCompanion extends TermLambdaCompanion[MethodType] { self =>
30323032

30333033
/** Produce method type from parameter symbols, with special mappings for repeated
3034-
* and transparent parameters:
3034+
* and inline parameters:
30353035
* - replace @repeated annotations on Seq or Array types by <repeated> types
3036-
* - add @inlineParam to transparent call-by-value parameters
3036+
* - add @inlineParam to inline call-by-value parameters
30373037
*/
30383038
def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = {
3039-
def translateTransparent(tp: Type): Type = tp match {
3039+
def translateInline(tp: Type): Type = tp match {
30403040
case _: ExprType => tp
3041-
case _ => AnnotatedType(tp, Annotation(defn.TransparentParamAnnot))
3041+
case _ => AnnotatedType(tp, Annotation(defn.InlineParamAnnot))
30423042
}
30433043
def paramInfo(param: Symbol) = {
30443044
val paramType = param.info.annotatedToRepeated
3045-
if (param.is(Transparent)) translateTransparent(paramType) else paramType
3045+
if (param.is(Inline)) translateInline(paramType) else paramType
30463046
}
30473047

30483048
apply(params.map(_.name.asTermName))(

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,8 @@ Standard-Section: "ASTs" TopLevelStat*
183183
ERASED
184184
LAZY
185185
OVERRIDE
186-
TRANSPARENT
187-
REWRITE
188-
MACRO // rewrite method containing toplevel splices
186+
INLINE
187+
MACRO // inline method containing toplevel splices
189188
STATIC // mapped to static Java member
190189
OBJECT // an object or its class
191190
TRAIT // a trait
@@ -299,8 +298,8 @@ object TastyFormat {
299298
final val IMPLICIT = 13
300299
final val LAZY = 14
301300
final val OVERRIDE = 15
302-
final val TRANSPARENT = 16
303-
final val REWRITE = 17
301+
302+
final val INLINE = 17
304303
final val STATIC = 18
305304
final val OBJECT = 19
306305
final val TRAIT = 20
@@ -481,8 +480,7 @@ object TastyFormat {
481480
| ERASED
482481
| LAZY
483482
| OVERRIDE
484-
| TRANSPARENT
485-
| REWRITE
483+
| INLINE
486484
| MACRO
487485
| STATIC
488486
| OBJECT
@@ -539,8 +537,7 @@ object TastyFormat {
539537
case ERASED => "ERASED"
540538
case LAZY => "LAZY"
541539
case OVERRIDE => "OVERRIDE"
542-
case TRANSPARENT => "TRANSPARENT"
543-
case REWRITE => "REWRITE"
540+
case INLINE => "INLINE"
544541
case MACRO => "MACRO"
545542
case STATIC => "STATIC"
546543
case OBJECT => "OBJECT"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -616,8 +616,7 @@ class TreePickler(pickler: TastyPickler) {
616616
if (flags.is(Final, butNot = Module)) writeByte(FINAL)
617617
if (flags is Case) writeByte(CASE)
618618
if (flags is Override) writeByte(OVERRIDE)
619-
if (flags is Transparent) writeByte(TRANSPARENT)
620-
if (flags is Rewrite) writeByte(REWRITE)
619+
if (flags is Inline) writeByte(INLINE)
621620
if (flags is Macro) writeByte(MACRO)
622621
if (flags is JavaStatic) writeByte(STATIC)
623622
if (flags is Module) writeByte(OBJECT)
@@ -782,13 +781,13 @@ class TreePickler(pickler: TastyPickler) {
782781
case If(cond, thenp, elsep) =>
783782
writeByte(IF)
784783
withLength {
785-
if (tree.isInstanceOf[untpd.RewriteIf]) writeByte(REWRITE)
784+
if (tree.isInstanceOf[untpd.InlineIf]) writeByte(INLINE)
786785
pickleUntyped(cond); pickleUntyped(thenp); pickleUntyped(elsep)
787786
}
788787
case Match(selector, cases) =>
789788
writeByte(MATCH)
790789
withLength {
791-
if (tree.isInstanceOf[untpd.RewriteMatch]) writeByte(REWRITE)
790+
if (tree.isInstanceOf[untpd.InlineMatch]) writeByte(INLINE)
792791
pickleUntyped(selector); cases.foreach(pickleUntyped)
793792
}
794793
case CaseDef(pat, guard, rhs) =>

0 commit comments

Comments
 (0)