Skip to content

Apply refactorings blocked previously #6791

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ object desugar {
}

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

/** Expand
*
Expand Down
14 changes: 10 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Decorators.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package dotty.tools.dotc
package dotty.tools
package dotc
package core

import annotation.tailrec
Expand Down Expand Up @@ -168,11 +169,16 @@ object Decorators {
}
}

implicit class genericDeco[T](val x: T) extends AnyVal {
def reporting(op: T => String, printer: config.Printers.Printer = config.Printers.default): T = {
printer.println(op(x))
implicit object reportDeco {
def (x: T) reporting[T](
op: given WrappedResult[T] => String,
printer: config.Printers.Printer = config.Printers.default): T = {
printer.println(op given WrappedResult(x))
x
}
}

implicit class genericDeco[T](val x: T) extends AnyVal {
def assertingErrorsReported(implicit ctx: Context): T = {
assert(ctx.reporter.errorsReported)
x
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ object Denotations {

def atSignature(sig: Signature, site: Type, relaxed: Boolean)(implicit ctx: Context): SingleDenotation = {
val situated = if (site == NoPrefix) this else asSeenFrom(site)
val matches = sig.matchDegree(situated.signature) >=
(if (relaxed) Signature.ParamMatch else Signature.FullMatch)
val matches = sig.matchDegree(situated.signature).ordinal >=
(if (relaxed) Signature.ParamMatch else Signature.FullMatch).ordinal
if (matches) this else NoDenotation
}

Expand Down Expand Up @@ -1096,7 +1096,7 @@ object Denotations {
d == Signature.FullMatch &&
!infoOrCompleter.isInstanceOf[PolyType] && !other.infoOrCompleter.isInstanceOf[PolyType]
||
d >= Signature.ParamMatch && info.matches(other.info))
d != Signature.NoMatch && info.matches(other.info))
}

def mapInherited(ownDenots: PreDenotation, prevDenots: PreDenotation, pre: Type)(implicit ctx: Context): SingleDenotation =
Expand Down
6 changes: 1 addition & 5 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ object Flags {
opaque type Flag <: FlagSet = Long
private[Flags] def Flag(bits: Long): Flag = bits
}
type FlagSet = opaques.FlagSet
def FlagSet(bits: Long): FlagSet = opaques.FlagSet(bits)
// DOTTY TODO: replace previous 2 lines with
// export opaques.FlagSet
// once 0.17 is released and #6721 is in the bootstrap
export opaques.FlagSet

type Flag = opaques.Flag
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also be exported?

Copy link
Contributor Author

@odersky odersky Jul 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

export opaques.Flag would also export the def Flag, rendering it public. This is not what we want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that method not defined as private? What happens when you export a private method?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even though it is private[Flags] and is exported into Flags object, this is technically fine with the contract of the private[Flags](namely that it should not be exposed outside Flags). If we don't want it in Flags either, shouldn't it be private[opaques]?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(except that we're using it in Flags, e.g. in newFlags:

opaques.Flag(KINDFLAGS | bits), opaques.Flag(TERMS | bits), opaques.Flag(TYPES | bits)

This would have been simplified if we exported the method)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An exported member is always public.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That does create problems when doing export x._. It can well become an antipattern as you must now be concerned with the private details of the implementation of x to do the export correctly. I don't know of any other case where this insight into private members would be required.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An export only exports members that are visible at the point of export. But then the forwarders become public. I think that's the right tradeoff.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense


Expand Down
13 changes: 6 additions & 7 deletions compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ final class ProperGadtConstraint private(
}

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

override def addBound(sym: Symbol, bound: Type, isUpper: Boolean)(implicit ctx: Context): Boolean = {
Expand Down Expand Up @@ -159,7 +158,7 @@ final class ProperGadtConstraint private(
val oldUpperBound = bounds(symTvar.origin)
// If we have bounds:
// F >: [t] => List[t] <: [t] => Any
// and we want to record that:
// and we want to record that:
// F <: [+A] => List[A]
// we need to adapt the variance and instead record that:
// F <: [A] => List[A]
Expand All @@ -177,10 +176,10 @@ final class ProperGadtConstraint private(
if (isUpper) addUpperBound(symTvar.origin, bound1)
else addLowerBound(symTvar.origin, bound1)
}
).reporting({ res =>
).reporting({
val descr = if (isUpper) "upper" else "lower"
val op = if (isUpper) "<:" else ">:"
i"adding $descr bound $sym $op $bound = $res"
i"adding $descr bound $sym $op $bound = $result"
}, gadts)
}

Expand All @@ -206,7 +205,7 @@ final class ProperGadtConstraint private(
case tb => tb
}
retrieveBounds
//.reporting({ res => i"gadt bounds $sym: $res" }, gadts)
//.reporting(i"gadt bounds $sym: $result", gadts)
//.ensuring(containsNoInternalTypes(_))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
merge(this.boundsMap, that.boundsMap, mergeEntries),
merge(this.lowerMap, that.lowerMap, mergeParams),
merge(this.upperMap, that.upperMap, mergeParams))
}.reporting(res => i"constraint merge $this with $other = $res", constr)
}.reporting(i"constraint merge $this with $other = $result", constr)

def rename(tl: TypeLambda)(implicit ctx: Context): OrderingConstraint = {
assert(contains(tl))
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/core/Signature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {

object Signature {

type MatchDegree = Int
val NoMatch: Int = 0
val ParamMatch: Int = 1
val FullMatch: Int = 2
enum MatchDegree {
case NoMatch, ParamMatch, FullMatch
}
export MatchDegree._

/** The signature of everything that's not a method, i.e. that has
* a type different from PolyType, MethodType, or ExprType.
Expand Down
36 changes: 12 additions & 24 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,46 +187,34 @@ object SymDenotations {
if (isCurrent(fs)) myFlags else flags

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

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

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

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

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

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

/** The type info, or, if symbol is not yet completed, the completer */
final def infoOrCompleter: Type = myInfo
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ object Symbols {
}
sourceFromTopLevel(ctx.withPhaseNoLater(ctx.flattenPhase))
}
}//.reporting(res => i"source of $this # $id in ${denot.owner} = $res")
}//.reporting(i"source of $this # $id in ${denot.owner} = $result")
mySource
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ trait MessageRendering {
else s"${pos.source.file.toString}: offset ${pos.start} (missing source file)"
val errId =
if (message.errorId ne ErrorMessageID.NoExplanationID) {
val errorNumber = message.errorId.errorNumber()
val errorNumber = message.errorId.errorNumber
s"[E${"0" * (3 - errorNumber.toString.length) + errorNumber}] "
} else ""
val kind =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package dotty.tools.dotc.reporting.diagnostic;
package dotty.tools.dotc.reporting.diagnostic

/** Unique IDs identifying the messages */
public enum ErrorMessageID {

// IMPORTANT: Add new IDs only at the end and never remove IDs
enum ErrorMessageID extends java.lang.Enum[ErrorMessageID] {

// IMPORTANT: Add new IDs only at the end and never remove IDs
case
LazyErrorId, // // errorNumber: -2
NoExplanationID, // errorNumber: -1

Expand Down Expand Up @@ -146,10 +146,6 @@ public enum ErrorMessageID {
StableIdentPatternID,
StaticFieldsShouldPrecedeNonStaticID,
IllegalSuperAccessorID
;

public int errorNumber() {
return ordinal() - 2;
}

def errorNumber = ordinal - 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -2154,11 +2154,13 @@ object messages {
val details = if (decl.isRealMethod && previousDecl.isRealMethod) {
// compare the signatures when both symbols represent methods
decl.signature.matchDegree(previousDecl.signature) match {
case Signature.NoMatch =>
case Signature.MatchDegree.NoMatch =>
// DOTTY problem: Need to qualify MatchDegree enum vals since otherwise exhaustivity fails.
// To fix this, we need to export vals under singleton types.
"" // shouldn't be reachable
case Signature.ParamMatch =>
case Signature.MatchDegree.ParamMatch =>
"have matching parameter types."
case Signature.FullMatch =>
case Signature.MatchDegree.FullMatch =>
i"have the same$nameAnd type after erasure."
}
} else ""
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import dotty.tools.dotc.util.SourceFile

import scala.tasty.reflect.Kernel

import delegate Flags.FlagOps // DOTTY problem: this line can be dropped in 0.17 once #6712 is in bootstrap.

class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.SourcePosition) extends Kernel {

private implicit def ctx: core.Contexts.Context = rootContext
Expand Down
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/CheckReentrant.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class CheckReentrant extends MiniPhase {

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

def scanning(sym: Symbol)(op: => Unit)(implicit ctx: Context): Unit = {
ctx.log(i"${" " * indent}scanning $sym")
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
if (idx >= 0 && idx < args.length) {
def finish(arg: Tree) =
new TreeTypeMap().transform(arg) // make sure local bindings in argument have fresh symbols
.reporting(res => i"projecting $tree -> $res", inlining)
.reporting(i"projecting $tree -> $result", inlining)
val arg = args(idx)
if (precomputed)
if (isPureExpr(arg)) finish(arg)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ object ProtoTypes {
resType match {
case SelectionProto(name: TermName, mbrType, _, _) =>
ctx.typer.hasExtensionMethod(tp, name, argType, mbrType)
//.reporting(res => i"has ext $tp $name $argType $mbrType: $res")
//.reporting(i"has ext $tp $name $argType $mbrType: $result")
case _ =>
false
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,7 @@ class Typer extends Namer
typed(untpd.Select(untpd.New(untpd.TypedSplice(tpt)), nme.CONSTRUCTOR), pt)
}
recur(tycon, pt)
.reporting(res => i"try new $tree -> $res", typr)
.reporting(i"try new $tree -> $result", typr)
}
} { (nu, nuState) =>
if (nu.isEmpty) fallBack
Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Variances.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package typer

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

object Variances {

Expand Down
9 changes: 9 additions & 0 deletions compiler/src/dotty/tools/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ package object tools {
/** Throws an `UnsupportedOperationException` with the given method name. */
def unsupported(methodName: String): Nothing =
throw new UnsupportedOperationException(methodName)

object resultWrapper {
opaque type WrappedResult[T] = T
private[tools] def unwrap[T](x: WrappedResult[T]): T = x
private[tools] def wrap[T](x: T): WrappedResult[T] = x
}
type WrappedResult[T] = resultWrapper.WrappedResult[T]
def WrappedResult[T](x: T) = resultWrapper.wrap(x)
def result[T] given (x: WrappedResult[T]): T = resultWrapper.unwrap(x)
}