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 =

0 commit comments

Comments
 (0)