Skip to content

Commit f951c6b

Browse files
committed
Rename transparent methods -> rewrite methods
Also implements rewrite matches and rewrite ifs. Keeps transparent as a separate modifier with meaning: "inline if called from a rewrite context".
1 parent 1abb405 commit f951c6b

File tree

254 files changed

+788
-851
lines changed

Some content is hidden

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

254 files changed

+788
-851
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-
transparent def power(transparent n: Long, x: Double) = ~powerCode(n, '(x))
5+
rewrite def power(transparent 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/CompilationUnit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import core.Types.Type // Do not remove me #3383
55
import util.SourceFile
66
import ast.{tpd, untpd}
77
import tpd.{ Tree, TreeTraverser }
8-
import typer.PrepareTransparent.InlineAccessors
8+
import typer.PrepareInlineable.InlineAccessors
99
import dotty.tools.dotc.core.Contexts.Context
1010
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1111
import dotty.tools.dotc.core.Symbols._

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import scala.io.Codec
1616
import util.{Set => _, _}
1717
import reporting.Reporter
1818
import transform.TreeChecker
19-
import rewrite.Rewrites
19+
import rewrites.Rewrites
2020
import java.io.{BufferedWriter, OutputStreamWriter}
2121

2222
import profile.Profiler

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
437437
def refPurity(tree: Tree)(implicit ctx: Context): PurityLevel = {
438438
val sym = tree.symbol
439439
if (!tree.hasType) Impure
440-
else if (!tree.tpe.widen.isParameterless || sym.is(Erased)) SimplyPure
440+
else if (!tree.tpe.widen.isParameterless || sym.isEffectivelyErased) SimplyPure
441441
else if (!sym.isStable) Impure
442442
else if (sym.is(Module))
443443
if (sym.moduleClass.isNoInitsClass) Pure else Idempotent

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,10 @@ 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])
501+
extends If(cond, thenp, elsep) {
502+
override def toString = s"RewriteIf($cond, $thenp, $elsep)"
503+
}
500504

501505
/** A closure with an environment and a reference to a method.
502506
* @param env The captured parameters of the closure
@@ -517,6 +521,10 @@ object Trees {
517521
extends TermTree[T] {
518522
type ThisTree[-T >: Untyped] = Match[T]
519523
}
524+
class RewriteMatch[T >: Untyped] private[ast] (selector: Tree[T], cases: List[CaseDef[T]])
525+
extends Match(selector, cases) {
526+
override def toString = s"RewriteMatch($selector, $cases)"
527+
}
520528

521529
/** case pat if guard => body; only appears as child of a Match */
522530
case class CaseDef[-T >: Untyped] private[ast] (pat: Tree[T], guard: Tree[T], body: Tree[T])
@@ -883,8 +891,10 @@ object Trees {
883891
type Assign = Trees.Assign[T]
884892
type Block = Trees.Block[T]
885893
type If = Trees.If[T]
894+
type RewriteIf = Trees.RewriteIf[T]
886895
type Closure = Trees.Closure[T]
887896
type Match = Trees.Match[T]
897+
type RewriteMatch = Trees.RewriteMatch[T]
888898
type CaseDef = Trees.CaseDef[T]
889899
type Return = Trees.Return[T]
890900
type Try = Trees.Try[T]
@@ -1013,6 +1023,9 @@ object Trees {
10131023
case _ => finalize(tree, untpd.Block(stats, expr))
10141024
}
10151025
def If(tree: Tree)(cond: Tree, thenp: Tree, elsep: Tree)(implicit ctx: Context): If = tree match {
1026+
case tree: RewriteIf =>
1027+
if ((cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep)) tree
1028+
else finalize(tree, untpd.RewriteIf(cond, thenp, elsep))
10161029
case tree: If if (cond eq tree.cond) && (thenp eq tree.thenp) && (elsep eq tree.elsep) => tree
10171030
case _ => finalize(tree, untpd.If(cond, thenp, elsep))
10181031
}
@@ -1021,6 +1034,9 @@ object Trees {
10211034
case _ => finalize(tree, untpd.Closure(env, meth, tpt))
10221035
}
10231036
def Match(tree: Tree)(selector: Tree, cases: List[CaseDef])(implicit ctx: Context): Match = tree match {
1037+
case tree: RewriteMatch =>
1038+
if ((selector eq tree.selector) && (cases eq tree.cases)) tree
1039+
else finalize(tree, untpd.RewriteMatch(selector, cases))
10241040
case tree: Match if (selector eq tree.selector) && (cases eq tree.cases) => tree
10251041
case _ => finalize(tree, untpd.Match(selector, cases))
10261042
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ 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+
135137
case class Transparent() extends Mod(Flags.Transparent)
136138

137139
case class Enum() extends Mod(Flags.Enum)
@@ -273,8 +275,10 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
273275
def Assign(lhs: Tree, rhs: Tree): Assign = new Assign(lhs, rhs)
274276
def Block(stats: List[Tree], expr: Tree): Block = new Block(stats, expr)
275277
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)
276279
def Closure(env: List[Tree], meth: Tree, tpt: Tree): Closure = new Closure(env, meth, tpt)
277280
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)
278282
def CaseDef(pat: Tree, guard: Tree, body: Tree): CaseDef = new CaseDef(pat, guard, body)
279283
def Return(expr: Tree, from: Tree): Return = new Return(expr, from)
280284
def Try(expr: Tree, cases: List[CaseDef], finalizer: Tree): Try = new Try(expr, cases, finalizer)
@@ -310,7 +314,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
310314
* where `Ts` are the class type arguments of `T` or its class type alias.
311315
* Note: we also keep any type arguments as parts of `T`. This is necessary to allow
312316
* navigation into these arguments from the IDE, and to do the right thing in
313-
* PrepareTransparent.
317+
* PrepareInlineable.
314318
*/
315319
def New(tpt: Tree, argss: List[List[Tree]])(implicit ctx: Context): Tree = {
316320
val (tycon, targs) = tpt match {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import java.io.File
55
import dotty.tools.io.{ Directory, PlainDirectory }
66

77
import PathResolver.Defaults
8-
import rewrite.Rewrites
8+
import rewrites.Rewrites
99

1010
class ScalaSettings extends Settings.SettingGroup {
1111

@@ -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 transparent method. Treated specially in
60+
* typically of a rewrite or transparent method. Treated specially in
6161
* pickling/unpickling and TypeTreeMaps
6262
*/
6363
abstract class BodyAnnotation extends Annotation {

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ object Contexts {
307307
def isNonEmptyScopeContext: Boolean =
308308
(this.scope ne outer.scope) && !this.scope.isEmpty
309309

310+
/** Is this a context for typechecking an inlined body? */
311+
def isInlineContext: Boolean =
312+
typer.isInstanceOf[Inliner#InlineTyper]
313+
310314
/** The next outer context whose tree is a template or package definition
311315
* Note: Currently unused
312316
def enclTemplate: Context = {

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

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

286+
/** Labelled with `rewrite` modifier */
287+
final val Rewrite = commonFlag(19, "rewrite")
288+
286289
/** A covariant type variable / an outer accessor */
287290
final val CovariantOrOuter = commonFlag(20, "")
288291
final val Covariant = typeFlag(20, "<covariant>")
@@ -433,7 +436,7 @@ object Flags {
433436

434437
/** Flags representing source modifiers */
435438
final val SourceModifierFlags =
436-
commonFlags(Private, Protected, Abstract, Final, Transparent,
439+
commonFlags(Private, Protected, Abstract, Final, Rewrite | Transparent,
437440
Sealed, Case, Implicit, Override, AbsOverride, Lazy, JavaStatic, Erased)
438441

439442
/** Flags representing modifiers that can appear in trees */
@@ -454,7 +457,7 @@ object Flags {
454457
Scala2ExistentialCommon | Mutable.toCommonFlags | Touched | JavaStatic |
455458
CovariantOrOuter | ContravariantOrLabel | CaseAccessor.toCommonFlags |
456459
NonMember | ImplicitCommon | Permanent | Synthetic |
457-
SuperAccessorOrScala2x | Transparent
460+
SuperAccessorOrScala2x | Rewrite | Transparent
458461

459462
/** Flags that are not (re)set when completing the denotation, or, if symbol is
460463
* a top-level class or object, when completing the denotation once the class
@@ -548,8 +551,8 @@ object Flags {
548551
/** Assumed to be pure */
549552
final val StableOrErased = Stable | Erased
550553

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

554557
/** A private method */
555558
final val PrivateMethod = allOf(Private, Method)
@@ -560,8 +563,11 @@ object Flags {
560563
/** A transparent method */
561564
final val TransparentMethod = allOf(Transparent, Method)
562565

563-
/** A transparent implicit method */
564-
final val TransparentImplicitMethod = allOf(Transparent, Implicit, Method)
566+
/** A rewrite method */
567+
final val RewriteMethod = allOf(Rewrite, Method)
568+
569+
/** An implicit rewrite method */
570+
final val ImplicitRewriteMethod = allOf(Rewrite, Implicit, Method)
565571

566572
/** A transparent parameter */
567573
final val TransparentParam = allOf(Transparent, Param)

0 commit comments

Comments
 (0)