Skip to content

Commit 39cd368

Browse files
committed
Make Transparent method imply Erased
Transparent methods are now always assumed to be erased. This required updating quote a few tests.
1 parent beca150 commit 39cd368

21 files changed

+37
-107
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class CheckRealizable(implicit ctx: Context) {
158158
private def memberRealizability(tp: Type) = {
159159
def checkField(sofar: Realizability, fld: SingleDenotation): Realizability =
160160
sofar andAlso {
161-
if (checkedFields.contains(fld.symbol) || fld.symbol.is(Private | Mutable | Lazy | Erased))
161+
if (checkedFields.contains(fld.symbol) || fld.symbol.is(Private | Mutable | LateInitialized))
162162
// if field is private it cannot be part of a visible path
163163
// if field is mutable it cannot be part of a path
164164
// if field is lazy or erased it does not need to be initialized when the owning object is

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,9 +560,6 @@ object Flags {
560560
/** A transparent method */
561561
final val TransparentMethod = allOf(Transparent, Method)
562562

563-
/** An erased transparent method */
564-
final val TypeLevelMethod = allOf(Transparent, Erased, Method)
565-
566563
/** A transparent parameter */
567564
final val TransparentParam = allOf(Transparent, Param)
568565

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,10 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
165165

166166
def markAsMacro(c: Context): Unit =
167167
if (c.owner eq c.outer.owner) markAsMacro(c.outer)
168-
else if (c.owner.isTransparentInlineable) c.owner.setFlag(Macro)
168+
else if (c.owner.isTransparentMethod) {
169+
c.owner.setFlag(Macro)
170+
c.owner.resetFlag(Erased) // FIXME: Macros should be Erased, but that causes problems right now
171+
}
169172
else if (!c.outer.owner.is(Package)) markAsMacro(c.outer)
170173

171174
if (sym.isSplice || sym.isQuote) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ object Splicer {
154154
try clazz.getMethod(name.toString, paramClasses: _*)
155155
catch {
156156
case _: NoSuchMethodException =>
157-
val msg = s"Could not find transparent macro method ${clazz.getCanonicalName}.$name with parameters $paramClasses$extraMsg"
157+
val msg = em"Could not find macro method ${clazz.getCanonicalName}.$name with parameters ($paramClasses%, %)$extraMsg"
158158
throw new StopInterpretation(msg, pos)
159159
}
160160
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,7 @@ class Namer { typer: Typer =>
11951195
instantiateDependent(restpe, typeParams, termParamss)
11961196
ctx.methodType(tparams map symbolOfTree, termParamss, restpe, isJava = ddef.mods is JavaDefined)
11971197
}
1198+
if (sym.is(Transparent)) sym.setFlag(Erased)
11981199
if (isConstructor) {
11991200
// set result type tree to unit, but take the current class as result type of the symbol
12001201
typedAheadType(ddef.tpt, defn.UnitType)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ object PrepareTransparent {
4848

4949
def markTopLevelMatches(meth: Symbol, tree: untpd.Tree)(implicit ctx: Context): Unit = tree match {
5050
case tree: untpd.Match =>
51-
meth.setFlag(Erased)
5251
tree.putAttachment(TopLevelMatch, ())
5352
tree.cases.foreach(markTopLevelMatches(meth, _))
5453
case tree: untpd.Block =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2351,7 +2351,7 @@ class Typer extends Namer
23512351
// - the current tree is a synthetic apply which is not expandable (eta-expasion would simply undo that)
23522352
if (arity >= 0 &&
23532353
!tree.symbol.isConstructor &&
2354-
!tree.symbol.is(TypeLevelMethod) &&
2354+
!tree.symbol.is(TransparentMethod) &&
23552355
!ctx.mode.is(Mode.Pattern) &&
23562356
!(isSyntheticApply(tree) && !isExpandableApply))
23572357
simplify(typed(etaExpand(tree, wtp, arity), pt), pt, locked)

library/src/dotty/runtime/LazyVals.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,20 @@ object LazyVals {
2525
final val LAZY_VAL_MASK = 3L
2626
final val debug = false
2727

28-
@forceInline def STATE(cur: Long, ord: Int) = {
28+
@inline def STATE(cur: Long, ord: Int) = {
2929
val r = (cur >> (ord * BITS_PER_LAZY_VAL)) & LAZY_VAL_MASK
3030
if (debug)
3131
println(s"STATE($cur, $ord) = $r")
3232
r
3333
}
34-
@forceInline def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int) = {
34+
@inline def CAS(t: Object, offset: Long, e: Long, v: Int, ord: Int) = {
3535
if (debug)
3636
println(s"CAS($t, $offset, $e, $v, $ord)")
3737
val mask = ~(LAZY_VAL_MASK << ord * BITS_PER_LAZY_VAL)
3838
val n = (e & mask) | (v.toLong << (ord * BITS_PER_LAZY_VAL))
3939
compareAndSet(t, offset, e, n)
4040
}
41-
@forceInline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = {
41+
@inline def setFlag(t: Object, offset: Long, v: Int, ord: Int) = {
4242
if (debug)
4343
println(s"setFlag($t, $offset, $v, $ord)")
4444
var retry = true
@@ -57,7 +57,7 @@ object LazyVals {
5757
}
5858
}
5959
}
60-
@forceInline def wait4Notification(t: Object, offset: Long, cur: Long, ord: Int) = {
60+
@inline def wait4Notification(t: Object, offset: Long, cur: Long, ord: Int) = {
6161
if (debug)
6262
println(s"wait4Notification($t, $offset, $cur, $ord)")
6363
var retry = true
@@ -75,8 +75,8 @@ object LazyVals {
7575
}
7676
}
7777

78-
@forceInline def compareAndSet(t: Object, off: Long, e: Long, v: Long) = unsafe.compareAndSwapLong(t, off, e, v)
79-
@forceInline def get(t: Object, off: Long) = {
78+
@inline def compareAndSet(t: Object, off: Long, e: Long, v: Long) = unsafe.compareAndSwapLong(t, off, e, v)
79+
@inline def get(t: Object, off: Long) = {
8080
if (debug)
8181
println(s"get($t, $off)")
8282
unsafe.getLongVolatile(t, off)
@@ -88,7 +88,7 @@ object LazyVals {
8888
x => new Object()
8989
}.toArray
9090

91-
@forceInline def getMonitor(obj: Object, fieldId: Int = 0) = {
91+
@inline def getMonitor(obj: Object, fieldId: Int = 0) = {
9292
var id = (
9393
/*java.lang.System.identityHashCode(obj) + */ // should be here, but #548
9494
fieldId) % base
@@ -97,7 +97,7 @@ object LazyVals {
9797
monitors(id)
9898
}
9999

100-
@forceInline def getOffset(clz: Class[_], name: String) = {
100+
@inline def getOffset(clz: Class[_], name: String) = {
101101
val r = unsafe.objectFieldOffset(clz.getDeclaredField(name))
102102
if (debug)
103103
println(s"getOffset($clz, $name) = $r")

tests/pos/inline-i1773.scala renamed to tests/neg/inline-i1773.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Test {
77
}
88

99
def main(args: Array[String]): Unit = {
10-
val q"class $name extends $parent" = new Object
10+
val q"class $name extends $parent" = new Object // error: method unapply is used
1111
println(name)
1212
println(parent)
1313
}

tests/pos/i3873.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ object Test {
22
transparent def sum2(ys: List[Int]): Unit = {
33
ys.foldLeft(1)
44
}
5-
val h1: ((List[Int]) => Unit) = sum2
5+
val h1 = (xs: List[Int]) => sum2(xs)
66
}

0 commit comments

Comments
 (0)