Skip to content

Commit cbc69fd

Browse files
authored
Merge pull request #6791 from dotty-staging/refactor-dotc
Apply refactorings blocked previously
2 parents ef62605 + a778f35 commit cbc69fd

19 files changed

+66
-70
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ object desugar {
766766
}
767767

768768
flatTree(cdef1 :: companions ::: implicitWrappers)
769-
}.reporting(res => i"desugared: $res", Printers.desugar)
769+
}.reporting(i"desugared: $result", Printers.desugar)
770770

771771
/** Expand
772772
*

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
package dotty.tools.dotc
1+
package dotty.tools
2+
package dotc
23
package core
34

45
import annotation.tailrec
@@ -168,11 +169,16 @@ object Decorators {
168169
}
169170
}
170171

171-
implicit class genericDeco[T](val x: T) extends AnyVal {
172-
def reporting(op: T => String, printer: config.Printers.Printer = config.Printers.default): T = {
173-
printer.println(op(x))
172+
implicit object reportDeco {
173+
def (x: T) reporting[T](
174+
op: given WrappedResult[T] => String,
175+
printer: config.Printers.Printer = config.Printers.default): T = {
176+
printer.println(op given WrappedResult(x))
174177
x
175178
}
179+
}
180+
181+
implicit class genericDeco[T](val x: T) extends AnyVal {
176182
def assertingErrorsReported(implicit ctx: Context): T = {
177183
assert(ctx.reporter.errorsReported)
178184
x

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -757,8 +757,8 @@ object Denotations {
757757

758758
def atSignature(sig: Signature, site: Type, relaxed: Boolean)(implicit ctx: Context): SingleDenotation = {
759759
val situated = if (site == NoPrefix) this else asSeenFrom(site)
760-
val matches = sig.matchDegree(situated.signature) >=
761-
(if (relaxed) Signature.ParamMatch else Signature.FullMatch)
760+
val matches = sig.matchDegree(situated.signature).ordinal >=
761+
(if (relaxed) Signature.ParamMatch else Signature.FullMatch).ordinal
762762
if (matches) this else NoDenotation
763763
}
764764

@@ -1096,7 +1096,7 @@ object Denotations {
10961096
d == Signature.FullMatch &&
10971097
!infoOrCompleter.isInstanceOf[PolyType] && !other.infoOrCompleter.isInstanceOf[PolyType]
10981098
||
1099-
d >= Signature.ParamMatch && info.matches(other.info))
1099+
d != Signature.NoMatch && info.matches(other.info))
11001100
}
11011101

11021102
def mapInherited(ownDenots: PreDenotation, prevDenots: PreDenotation, pre: Type)(implicit ctx: Context): SingleDenotation =

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ object Flags {
2020
opaque type Flag <: FlagSet = Long
2121
private[Flags] def Flag(bits: Long): Flag = bits
2222
}
23-
type FlagSet = opaques.FlagSet
24-
def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits)
25-
// DOTTY TODO: replace previous 2 lines with
26-
// export opaques.FlagSet
27-
// once 0.17 is released and #6721 is in the bootstrap
23+
export opaques.FlagSet
2824

2925
type Flag = opaques.Flag
3026

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ final class ProperGadtConstraint private(
123123
}
124124

125125
// The replaced symbols are picked up here.
126-
addToConstraint(poly1, tvars).reporting({ _ =>
127-
i"added to constraint: $params%, %\n$debugBoundsDescription"
128-
}, gadts)
126+
addToConstraint(poly1, tvars)
127+
.reporting(i"added to constraint: $params%, %\n$debugBoundsDescription", gadts)
129128
}
130129

131130
override def addBound(sym: Symbol, bound: Type, isUpper: Boolean)(implicit ctx: Context): Boolean = {
@@ -159,7 +158,7 @@ final class ProperGadtConstraint private(
159158
val oldUpperBound = bounds(symTvar.origin)
160159
// If we have bounds:
161160
// F >: [t] => List[t] <: [t] => Any
162-
// and we want to record that:
161+
// and we want to record that:
163162
// F <: [+A] => List[A]
164163
// we need to adapt the variance and instead record that:
165164
// F <: [A] => List[A]
@@ -177,10 +176,10 @@ final class ProperGadtConstraint private(
177176
if (isUpper) addUpperBound(symTvar.origin, bound1)
178177
else addLowerBound(symTvar.origin, bound1)
179178
}
180-
).reporting({ res =>
179+
).reporting({
181180
val descr = if (isUpper) "upper" else "lower"
182181
val op = if (isUpper) "<:" else ">:"
183-
i"adding $descr bound $sym $op $bound = $res"
182+
i"adding $descr bound $sym $op $bound = $result"
184183
}, gadts)
185184
}
186185

@@ -206,7 +205,7 @@ final class ProperGadtConstraint private(
206205
case tb => tb
207206
}
208207
retrieveBounds
209-
//.reporting({ res => i"gadt bounds $sym: $res" }, gadts)
208+
//.reporting(i"gadt bounds $sym: $result", gadts)
210209
//.ensuring(containsNoInternalTypes(_))
211210
}
212211
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
548548
merge(this.boundsMap, that.boundsMap, mergeEntries),
549549
merge(this.lowerMap, that.lowerMap, mergeParams),
550550
merge(this.upperMap, that.upperMap, mergeParams))
551-
}.reporting(res => i"constraint merge $this with $other = $res", constr)
551+
}.reporting(i"constraint merge $this with $other = $result", constr)
552552

553553
def rename(tl: TypeLambda)(implicit ctx: Context): OrderingConstraint = {
554554
assert(contains(tl))

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
107107

108108
object Signature {
109109

110-
type MatchDegree = Int
111-
val NoMatch: Int = 0
112-
val ParamMatch: Int = 1
113-
val FullMatch: Int = 2
110+
enum MatchDegree {
111+
case NoMatch, ParamMatch, FullMatch
112+
}
113+
export MatchDegree._
114114

115115
/** The signature of everything that's not a method, i.e. that has
116116
* a type different from PolyType, MethodType, or ExprType.

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

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,46 +187,34 @@ object SymDenotations {
187187
if (isCurrent(fs)) myFlags else flags
188188

189189
/** Has this denotation one of given flag set? */
190-
final def is(flag: Flag)(implicit ctx: Context): Boolean = {
191-
val toTest = if (isCurrent(flag)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in
192-
toTest.is(flag)
193-
}
190+
final def is(flag: Flag)(implicit ctx: Context): Boolean =
191+
(if (isCurrent(flag)) myFlags else flags).is(flag)
194192

195193
/** Has this denotation one of the flags in `fs` set? */
196-
final def isOneOf(fs: FlagSet)(implicit ctx: Context): Boolean = {
197-
val toTest = if (isCurrent(fs)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in
198-
toTest.isOneOf(fs)
199-
}
194+
final def isOneOf(fs: FlagSet)(implicit ctx: Context): Boolean =
195+
(if (isCurrent(fs)) myFlags else flags).isOneOf(fs)
200196

201197
/** Has this denotation the given flag set, whereas none of the flags
202198
* in `butNot` are set?
203199
*/
204-
final def is(flag: Flag, butNot: FlagSet)(implicit ctx: Context): Boolean = {
205-
val toTest = if (isCurrent(flag) && isCurrent(butNot)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in
206-
toTest.is(flag, butNot)
207-
}
200+
final def is(flag: Flag, butNot: FlagSet)(implicit ctx: Context): Boolean =
201+
(if (isCurrent(flag) && isCurrent(butNot)) myFlags else flags).is(flag, butNot)
208202

209203
/** Has this denotation one of the flags in `fs` set, whereas none of the flags
210204
* in `butNot` are set?
211205
*/
212-
final def isOneOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = {
213-
val toTest = if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in
214-
toTest.isOneOf(fs, butNot)
215-
}
206+
final def isOneOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean =
207+
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isOneOf(fs, butNot)
216208

217209
/** Has this denotation all of the flags in `fs` set? */
218-
final def isAllOf(fs: FlagSet)(implicit ctx: Context): Boolean = {
219-
val toTest = if (isCurrent(fs)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in
220-
toTest.isAllOf(fs)
221-
}
210+
final def isAllOf(fs: FlagSet)(implicit ctx: Context): Boolean =
211+
(if (isCurrent(fs)) myFlags else flags).isAllOf(fs)
222212

223213
/** Has this denotation all of the flags in `fs` set, whereas none of the flags
224214
* in `butNot` are set?
225215
*/
226-
final def isAllOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean = {
227-
val toTest = if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags // TODO: combine these two lines once 0.17 is released and #6706 is in
228-
toTest.isAllOf(fs, butNot)
229-
}
216+
final def isAllOf(fs: FlagSet, butNot: FlagSet)(implicit ctx: Context): Boolean =
217+
(if (isCurrent(fs) && isCurrent(butNot)) myFlags else flags).isAllOf(fs, butNot)
230218

231219
/** The type info, or, if symbol is not yet completed, the completer */
232220
final def infoOrCompleter: Type = myInfo

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ object Symbols {
794794
}
795795
sourceFromTopLevel(ctx.withPhaseNoLater(ctx.flattenPhase))
796796
}
797-
}//.reporting(res => i"source of $this # $id in ${denot.owner} = $res")
797+
}//.reporting(i"source of $this # $id in ${denot.owner} = $result")
798798
mySource
799799
}
800800

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ trait MessageRendering {
119119
else s"${pos.source.file.toString}: offset ${pos.start} (missing source file)"
120120
val errId =
121121
if (message.errorId ne ErrorMessageID.NoExplanationID) {
122-
val errorNumber = message.errorId.errorNumber()
122+
val errorNumber = message.errorId.errorNumber
123123
s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] "
124124
} else ""
125125
val kind =

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java renamed to compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.scala

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package dotty.tools.dotc.reporting.diagnostic;
1+
package dotty.tools.dotc.reporting.diagnostic
22

33
/** Unique IDs identifying the messages */
4-
public enum ErrorMessageID {
5-
6-
// IMPORTANT: Add new IDs only at the end and never remove IDs
4+
enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {
75

6+
// IMPORTANT: Add new IDs only at the end and never remove IDs
7+
case
88
LazyErrorId, // // errorNumber: -2
99
NoExplanationID, // errorNumber: -1
1010

@@ -146,10 +146,6 @@ public enum ErrorMessageID {
146146
StableIdentPatternID,
147147
StaticFieldsShouldPrecedeNonStaticID,
148148
IllegalSuperAccessorID
149-
;
150-
151-
public int errorNumber() {
152-
return ordinal() - 2;
153-
}
154149

150+
def errorNumber = ordinal - 2
155151
}

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,11 +2154,13 @@ object messages {
21542154
val details = if (decl.isRealMethod && previousDecl.isRealMethod) {
21552155
// compare the signatures when both symbols represent methods
21562156
decl.signature.matchDegree(previousDecl.signature) match {
2157-
case Signature.NoMatch =>
2157+
case Signature.MatchDegree.NoMatch =>
2158+
// DOTTY problem: Need to qualify MatchDegree enum vals since otherwise exhaustivity fails.
2159+
// To fix this, we need to export vals under singleton types.
21582160
"" // shouldn't be reachable
2159-
case Signature.ParamMatch =>
2161+
case Signature.MatchDegree.ParamMatch =>
21602162
"have matching parameter types."
2161-
case Signature.FullMatch =>
2163+
case Signature.MatchDegree.FullMatch =>
21622164
i"have the same$nameAnd type after erasure."
21632165
}
21642166
} else ""

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import dotty.tools.dotc.util.SourceFile
1717

1818
import scala.tasty.reflect.Kernel
1919

20-
import delegate Flags.FlagOps // DOTTY problem: this line can be dropped in 0.17 once #6712 is in bootstrap.
21-
2220
class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.SourcePosition) extends Kernel {
2321

2422
private implicit def ctx: core.Contexts.Context = rootContext

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ class CheckReentrant extends MiniPhase {
4343

4444
def isIgnored(sym: Symbol)(implicit ctx: Context): Boolean =
4545
sym.hasAnnotation(sharableAnnot()) ||
46-
sym.hasAnnotation(unsharedAnnot())
46+
sym.hasAnnotation(unsharedAnnot()) ||
47+
sym.owner == defn.EnumValuesClass
48+
// enum values are initialized eagerly before use
49+
// in the long run, we should make them vals
4750

4851
def scanning(sym: Symbol)(op: => Unit)(implicit ctx: Context): Unit = {
4952
ctx.log(i"${" " * indent}scanning $sym")

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
629629
if (idx >= 0 && idx < args.length) {
630630
def finish(arg: Tree) =
631631
new TreeTypeMap().transform(arg) // make sure local bindings in argument have fresh symbols
632-
.reporting(res => i"projecting $tree -> $res", inlining)
632+
.reporting(i"projecting $tree -> $result", inlining)
633633
val arg = args(idx)
634634
if (precomputed)
635635
if (isPureExpr(arg)) finish(arg)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ object ProtoTypes {
401401
resType match {
402402
case SelectionProto(name: TermName, mbrType, _, _) =>
403403
ctx.typer.hasExtensionMethod(tp, name, argType, mbrType)
404-
//.reporting(res => i"has ext $tp $name $argType $mbrType: $res")
404+
//.reporting(i"has ext $tp $name $argType $mbrType: $result")
405405
case _ =>
406406
false
407407
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2565,7 +2565,7 @@ class Typer extends Namer
25652565
typed(untpd.Select(untpd.New(untpd.TypedSplice(tpt)), nme.CONSTRUCTOR), pt)
25662566
}
25672567
recur(tycon, pt)
2568-
.reporting(res => i"try new $tree -> $res", typr)
2568+
.reporting(i"try new $tree -> $result", typr)
25692569
}
25702570
} { (nu, nuState) =>
25712571
if (nu.isEmpty) fallBack

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package typer
33

44
import core._
55
import Types._, Contexts._, Flags._, Symbols._, Annotations._
6-
import delegate Flags.FlagOps // DOTTY problem: this line can be dropped in 0.17 once #6712 is in bootstrap.
76

87
object Variances {
98

compiler/src/dotty/tools/package.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,13 @@ package object tools {
2323
/** Throws an `UnsupportedOperationException` with the given method name. */
2424
def unsupported(methodName: String): Nothing =
2525
throw new UnsupportedOperationException(methodName)
26+
27+
object resultWrapper {
28+
opaque type WrappedResult[T] = T
29+
private[tools] def unwrap[T](x: WrappedResult[T]): T = x
30+
private[tools] def wrap[T](x: T): WrappedResult[T] = x
31+
}
32+
type WrappedResult[T] = resultWrapper.WrappedResult[T]
33+
def WrappedResult[T](x: T) = resultWrapper.wrap(x)
34+
def result[T] given (x: WrappedResult[T]): T = resultWrapper.unwrap(x)
2635
}

0 commit comments

Comments
 (0)