Skip to content

Commit 0fbda2e

Browse files
committed
Remove transparent parameters and use Constant types instead
1 parent 68cf530 commit 0fbda2e

Some content is hidden

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

43 files changed

+99
-111
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+
transparent def power(n: Long & Constant, 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/core/Definitions.scala

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ class Definitions {
415415
enterCompleteClassSymbol(
416416
ScalaPackageClass, tpnme.Constant, PureInterfaceCreationFlags | Final,
417417
List(SingletonType), EmptyScope)
418-
lazy val ConstantType: TypeRef = ConstantClass.typeRef
419418

420419
lazy val SeqType: TypeRef =
421420
if (isNewCollections) ctx.requiredClassRef("scala.collection.immutable.Seq")
@@ -741,8 +740,6 @@ class Definitions {
741740
def ImplicitNotFoundAnnot(implicit ctx: Context) = ImplicitNotFoundAnnotType.symbol.asClass
742741
lazy val ForceInlineAnnotType = ctx.requiredClassRef("scala.forceInline")
743742
def ForceInlineAnnot(implicit ctx: Context) = ForceInlineAnnotType.symbol.asClass
744-
lazy val TransparentParamAnnotType = ctx.requiredClassRef("scala.annotation.internal.TransparentParam")
745-
def TransparentParamAnnot(implicit ctx: Context) = TransparentParamAnnotType.symbol.asClass
746743
lazy val InvariantBetweenAnnotType = ctx.requiredClassRef("scala.annotation.internal.InvariantBetween")
747744
def InvariantBetweenAnnot(implicit ctx: Context) = InvariantBetweenAnnotType.symbol.asClass
748745
lazy val MigrationAnnotType = ctx.requiredClassRef("scala.annotation.migration")

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,6 @@ object Flags {
563563
/** A transparent implicit method */
564564
final val TransparentImplicitMethod = allOf(Transparent, Implicit, Method)
565565

566-
/** A transparent parameter */
567-
final val TransparentParam = allOf(Transparent, Param)
568-
569566
/** An enum case */
570567
final val EnumCase = allOf(Enum, Case)
571568

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

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3016,15 +3016,8 @@ object Types {
30163016
* - add @inlineParam to transparent call-by-value parameters
30173017
*/
30183018
def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = {
3019-
def translateTransparent(tp: Type): Type = tp match {
3020-
case _: ExprType => tp
3021-
case _ => AnnotatedType(tp, Annotation(defn.TransparentParamAnnot))
3022-
}
3023-
def paramInfo(param: Symbol) = {
3024-
val paramType = param.info.annotatedToRepeated
3025-
if (param.is(Transparent)) translateTransparent(paramType) else paramType
3026-
}
3027-
3019+
def paramInfo(param: Symbol) =
3020+
param.info.annotatedToRepeated
30283021
apply(params.map(_.name.asTermName))(
30293022
tl => params.map(p => tl.integrate(params, paramInfo(p))),
30303023
tl => tl.integrate(params, resultType))

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,12 +1913,12 @@ object Parsers {
19131913
/** ClsParamClauses ::= {ClsParamClause} [[nl] `(' [FunArgMods] ClsParams `)']
19141914
* ClsParamClause ::= [nl] `(' [`erased'] [ClsParams] ')'
19151915
* ClsParams ::= ClsParam {`' ClsParam}
1916-
* ClsParam ::= {Annotation} [{Modifier} (`val' | `var') | `inline'] Param
1916+
* ClsParam ::= {Annotation} [{Modifier} (`val' | `var')] Param
19171917
* DefParamClauses ::= {DefParamClause} [[nl] `(' [FunArgMods] DefParams `)']
19181918
* DefParamClause ::= [nl] `(' [`erased'] [DefParams] ')'
19191919
* DefParams ::= DefParam {`,' DefParam}
1920-
* DefParam ::= {Annotation} [`inline'] Param
1921-
* Param ::= id `:' ParamType [`=' Expr]
1920+
* DefParam ::= {Annotation} Param
1921+
* Param ::= id :' ParamType [`=' Expr]
19221922
*/
19231923
def paramClauses(owner: Name, ofCaseClass: Boolean = false): List[List[ValDef]] = {
19241924
var imods: Modifiers = EmptyModifiers
@@ -1940,15 +1940,14 @@ object Parsers {
19401940
addMod(mods, mod)
19411941
}
19421942
else {
1943-
if (!(mods.flags &~ (ParamAccessor | Transparent)).isEmpty)
1943+
if (!(mods.flags &~ ParamAccessor).isEmpty)
19441944
syntaxError("`val' or `var' expected")
19451945
if (firstClauseOfCaseClass) mods
19461946
else mods | PrivateLocal
19471947
}
19481948
}
19491949
}
19501950
else {
1951-
if (in.token == TRANSPARENT) mods = addModifier(mods)
19521951
mods = atPos(start) { mods | Param }
19531952
}
19541953
atPos(start, nameStart) {

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
254254
super.transform(_).asInstanceOf[Template]))
255255
}
256256
case tree: ValDef =>
257+
if (tree.symbol.is(Param) && !tree.symbol.owner.is(Transparent) && tree.tpt.tpe.derivesFrom(defn.ConstantClass))
258+
ctx.error("only parameters of transparent method can have Constant type", tree.pos)
257259
val tree1 = cpy.ValDef(tree)(rhs = normalizeErasedRhs(tree.rhs, tree.symbol))
258260
transformMemberDef(tree1)
259261
super.transform(tree1)

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
504504
val captured = mutable.LinkedHashMap.empty[Symbol, Tree]
505505
val captured2 = capturer(captured)
506506

507-
outer.enteredSyms.foreach(sym => if (!sym.is(Transparent)) capturers.put(sym, captured2))
507+
outer.enteredSyms.foreach(sym => if (!sym.info.derivesFrom(defn.ConstantClass)) capturers.put(sym, captured2))
508508

509509
val tree2 = transform(tree)
510510
capturers --= outer.enteredSyms
@@ -550,7 +550,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
550550
splice(ref(splicedType).select(tpnme.UNARY_~).withPos(tree.pos))
551551
case tree: Select if tree.symbol.isSplice =>
552552
splice(tree)
553-
case tree: RefTree if tree.symbol.is(Transparent) && tree.symbol.is(Param) =>
553+
case tree: RefTree if tree.symbol.is(Param) && tree.tpe.derivesFrom(defn.ConstantClass) =>
554554
tree
555555
case tree: RefTree if isCaptured(tree.symbol, level) =>
556556
val t = capturers(tree.symbol).apply(tree)

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,9 @@ object Splicer {
240240

241241
def unexpectedTree(tree: tpd.Tree)(implicit env: Env): Boolean = {
242242
// Assuming that top-level splices can only be in transparent methods
243-
// and splices are expanded at inline site, references to transparent values
243+
// and splices are expanded at inline site, references to parameter wit constant type
244244
// will be know literal constant trees.
245-
tree.symbol.is(Transparent)
245+
tree.symbol.is(Param) && tree.tpe.derivesFrom(defn.ConstantClass)
246246
}
247247
}
248248

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
221221
bindingsBuf: mutable.ListBuffer[MemberDef]): MemberDef = {
222222
val argtpe = arg.tpe.dealiasKeepAnnots
223223
val isByName = paramtp.dealias.isInstanceOf[ExprType]
224-
val inlineFlag = if (paramtp.hasAnnotation(defn.TransparentParamAnnot)) Transparent else EmptyFlags
225224
val (bindingFlags, bindingType) =
226225
if (isByName) (Method, ExprType(argtpe.widen))
227-
else (inlineFlag, argtpe.widen)
226+
else (EmptyFlags, argtpe.widen)
228227
val boundSym = newSym(name, bindingFlags, bindingType).asTerm
229228
val binding =
230229
if (isByName) DefDef(boundSym, arg.changeOwner(ctx.owner, boundSym))

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2385,8 +2385,6 @@ class Typer extends Namer
23852385
readaptSimplified(Inliner.inlineCall(tree, pt))
23862386
}
23872387
else if (tree.tpe <:< pt) {
2388-
if (pt.hasAnnotation(defn.TransparentParamAnnot))
2389-
checkTransparentConformant(tree, isFinal = false, "argument to transparent parameter")
23902388
if (ctx.typeComparer.GADTused && pt.isValueType)
23912389
// Insert an explicit cast, so that -Ycheck in later phases succeeds.
23922390
// I suspect, but am not 100% sure that this might affect inferred types,

0 commit comments

Comments
 (0)