aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
authorDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-27 12:53:03 +0100
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-03-27 15:02:53 +0100
commit97faee5a82b40b4c980c8cb222ff5ac4cb9083a4 (patch)
tree760353c5f86d35d473a54ba2ba71a4b0f55ddd41 /src/dotty/tools/dotc/typer
parenta6419fbd80bb63413de671af331ae35da4fa4e1b (diff)
downloaddotty-97faee5a82b40b4c980c8cb222ff5ac4cb9083a4.tar.gz
dotty-97faee5a82b40b4c980c8cb222ff5ac4cb9083a4.tar.bz2
dotty-97faee5a82b40b4c980c8cb222ff5ac4cb9083a4.zip
Rename methods on FreshContext to make mutation obvious
And avoid name clashes
Diffstat (limited to 'src/dotty/tools/dotc/typer')
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala4
-rw-r--r--src/dotty/tools/dotc/typer/FrontEnd.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Implicits.scala18
-rw-r--r--src/dotty/tools/dotc/typer/Inferencing.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Namer.scala14
-rw-r--r--src/dotty/tools/dotc/typer/ProtoTypes.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala20
7 files changed, 31 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 46a6ebf66..9a21e1c54 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -712,7 +712,7 @@ trait Applications extends Compatibility { self: Typer =>
* @param resultType The expected result type of the application
*/
def isApplicable(methRef: TermRef, targs: List[Type], args: List[Tree], resultType: Type)(implicit ctx: Context): Boolean = {
- val nestedContext = ctx.fresh.withExploreTyperState
+ val nestedContext = ctx.fresh.setExploreTyperState
new ApplicableToTrees(methRef, targs, args, resultType)(nestedContext).success
}
@@ -720,7 +720,7 @@ trait Applications extends Compatibility { self: Typer =>
* @param resultType The expected result type of the application
*/
def isApplicable(methRef: TermRef, args: List[Type], resultType: Type)(implicit ctx: Context): Boolean = {
- val nestedContext = ctx.fresh.withExploreTyperState
+ val nestedContext = ctx.fresh.setExploreTyperState
new ApplicableToTypes(methRef, args, resultType)(nestedContext).success
}
diff --git a/src/dotty/tools/dotc/typer/FrontEnd.scala b/src/dotty/tools/dotc/typer/FrontEnd.scala
index 0161c1f6f..697830fb1 100644
--- a/src/dotty/tools/dotc/typer/FrontEnd.scala
+++ b/src/dotty/tools/dotc/typer/FrontEnd.scala
@@ -41,7 +41,7 @@ class FrontEnd extends Phase {
}
override def runOn(units: List[CompilationUnit])(implicit ctx: Context): Unit = {
- val unitContexts = units map (unit => ctx.fresh.withCompilationUnit(unit))
+ val unitContexts = units map (unit => ctx.fresh.setCompilationUnit(unit))
unitContexts foreach (parse(_))
record("parsedTrees", ast.Trees.ntrees)
unitContexts foreach (enterSyms(_))
diff --git a/src/dotty/tools/dotc/typer/Implicits.scala b/src/dotty/tools/dotc/typer/Implicits.scala
index fe1c938c9..8990d21a2 100644
--- a/src/dotty/tools/dotc/typer/Implicits.scala
+++ b/src/dotty/tools/dotc/typer/Implicits.scala
@@ -50,13 +50,13 @@ object Implicits {
case mt: MethodType =>
mt.isImplicit ||
mt.paramTypes.length != 1 ||
- !(argType <:< mt.paramTypes.head)(ctx.fresh.withExploreTyperState)
+ !(argType <:< mt.paramTypes.head)(ctx.fresh.setExploreTyperState)
case poly: PolyType =>
poly.resultType match {
case mt: MethodType =>
mt.isImplicit ||
mt.paramTypes.length != 1 ||
- !(argType <:< wildApprox(mt.paramTypes.head)(ctx.fresh.withExploreTyperState))
+ !(argType <:< wildApprox(mt.paramTypes.head)(ctx.fresh.setExploreTyperState))
case rtp =>
discardForView(wildApprox(rtp), argType)
}
@@ -90,7 +90,7 @@ object Implicits {
}
if (refs.isEmpty) refs
- else refs filter (refMatches(_)(ctx.fresh.withExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution
+ else refs filter (refMatches(_)(ctx.fresh.setExploreTyperState.addMode(Mode.TypevarsMissContext))) // create a defensive copy of ctx to avoid constraint pollution
}
}
@@ -370,7 +370,7 @@ trait Implicits { self: Typer =>
}
case _ =>
}
- inferView(dummyTreeOfType(from), to)(ctx.fresh.withExploreTyperState).isInstanceOf[SearchSuccess]
+ inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess]
}
)
@@ -419,7 +419,7 @@ trait Implicits { self: Typer =>
/** An implicit search; parameters as in `inferImplicit` */
class ImplicitSearch(protected val pt: Type, protected val argument: Tree, pos: Position)(implicit ctx: Context) {
- private def nestedContext = ctx.fresh.withNewMode(ctx.mode &~ Mode.ImplicitsEnabled)
+ private def nestedContext = ctx.fresh.setMode(ctx.mode &~ Mode.ImplicitsEnabled)
private def implicitProto(resultType: Type, f: Type => Type) =
if (argument.isEmpty) f(resultType) else ViewProto(f(argument.tpe.widen), f(resultType))
@@ -457,7 +457,7 @@ trait Implicits { self: Typer =>
pt)
val generated1 = adapt(generated, pt)
lazy val shadowing =
- typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.withNewTyperState)
+ typed(untpd.Ident(ref.name) withPos pos.toSynthetic, funProto)(nestedContext.clearTyperState)
def refMatches(shadowing: Tree): Boolean =
ref.symbol == closureBody(shadowing).symbol || {
shadowing match {
@@ -485,12 +485,12 @@ trait Implicits { self: Typer =>
val history = ctx.searchHistory nest wildProto
val result =
if (history eq ctx.searchHistory) divergingImplicit(ref)
- else typedImplicit(ref)(nestedContext.withNewTyperState.withSearchHistory(history))
+ else typedImplicit(ref)(nestedContext.clearTyperState.setSearchHistory(history))
result match {
case fail: SearchFailure =>
rankImplicits(pending1, acc)
case best: SearchSuccess =>
- val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.withExploreTyperState))
+ val newPending = pending1 filter (isAsGood(_, best.ref)(nestedContext.setExploreTyperState))
rankImplicits(newPending, best :: acc)
}
case nil => acc
@@ -499,7 +499,7 @@ trait Implicits { self: Typer =>
/** Convert a (possibly empty) list of search successes into a single search result */
def condense(hits: List[SearchSuccess]): SearchResult = hits match {
case best :: alts =>
- alts find (alt => isAsGood(alt.ref, best.ref)(ctx.fresh.withExploreTyperState)) match {
+ alts find (alt => isAsGood(alt.ref, best.ref)(ctx.fresh.setExploreTyperState)) match {
case Some(alt) =>
/* !!! DEBUG
println(i"ambiguous refs: ${hits map (_.ref) map (_.show) mkString ", "}")
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala
index 6d9afecab..9c4ce232e 100644
--- a/src/dotty/tools/dotc/typer/Inferencing.scala
+++ b/src/dotty/tools/dotc/typer/Inferencing.scala
@@ -30,7 +30,7 @@ trait Inferencing { this: Checking =>
* Variables that are successfully minimized do not count as uninstantiated.
*/
def isFullyDefined(tp: Type, force: ForceDegree.Value)(implicit ctx: Context): Boolean = {
- val nestedCtx = ctx.fresh.withNewTyperState
+ val nestedCtx = ctx.fresh.clearTyperState
val result = new IsFullyDefinedAccumulator(force)(nestedCtx).process(tp)
if (result) nestedCtx.typerState.commit()
result
diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala
index 361de802c..e81949f05 100644
--- a/src/dotty/tools/dotc/typer/Namer.scala
+++ b/src/dotty/tools/dotc/typer/Namer.scala
@@ -288,11 +288,11 @@ class Namer { typer: Typer =>
/** A new context that summarizes an import statement */
def importContext(sym: Symbol, selectors: List[Tree])(implicit ctx: Context) =
- ctx.fresh.withImportInfo(new ImportInfo(sym, selectors))
+ ctx.fresh.setImportInfo(new ImportInfo(sym, selectors))
/** A new context for the interior of a class */
def inClassContext(selfInfo: DotClass /* Should be Type | Symbol*/)(implicit ctx: Context): Context = {
- val localCtx: Context = ctx.fresh.withNewScope
+ val localCtx: Context = ctx.fresh.clearScope
selfInfo match {
case sym: Symbol if sym.exists && sym.name != nme.WILDCARD =>
localCtx.scope.asInstanceOf[MutableScope].enter(sym)
@@ -330,7 +330,7 @@ class Namer { typer: Typer =>
def indexExpanded(stat: Tree)(implicit ctx: Context): Context = expanded(stat) match {
case pcl: PackageDef =>
val pkg = createPackageSymbol(pcl.pid)
- index(pcl.stats)(ctx.fresh.withOwner(pkg.moduleClass))
+ index(pcl.stats)(ctx.fresh.setOwner(pkg.moduleClass))
invalidateCompanions(pkg, Trees.flatten(pcl.stats map expanded))
ctx
case imp: Import =>
@@ -380,19 +380,19 @@ class Namer { typer: Typer =>
/** The completer of a symbol defined by a member def or import (except ClassSymbols) */
class Completer(val original: Tree)(implicit ctx: Context) extends LazyType {
- protected def localContext(owner: Symbol) = ctx.fresh.withOwner(owner).withTree(original)
+ protected def localContext(owner: Symbol) = ctx.fresh.setOwner(owner).setTree(original)
private def typeSig(sym: Symbol): Type = original match {
case original: ValDef =>
if (sym is Module) moduleValSig(sym)
- else valOrDefDefSig(original, sym, Nil, identity)(localContext(sym).withNewScope)
+ else valOrDefDefSig(original, sym, Nil, identity)(localContext(sym).clearScope)
case original: DefDef =>
val typer1 = new Typer
nestedTyper(sym) = typer1
- typer1.defDefSig(original, sym)(localContext(sym).withTyper(typer1))
+ typer1.defDefSig(original, sym)(localContext(sym).setTyper(typer1))
case original: TypeDef =>
assert(!original.isClassDef)
- typeDefSig(original, sym)(localContext(sym).withNewScope)
+ typeDefSig(original, sym)(localContext(sym).clearScope)
case imp: Import =>
try {
val expr1 = typedAheadExpr(imp.expr, AnySelectionProto)
diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala
index 16fcc9db7..16869454f 100644
--- a/src/dotty/tools/dotc/typer/ProtoTypes.scala
+++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala
@@ -38,7 +38,7 @@ object ProtoTypes {
/** Test compatibility after normalization in a fresh typerstate. */
def normalizedCompatible(tp: Type, pt: Type)(implicit ctx: Context) = {
- val nestedCtx = ctx.fresh.withExploreTyperState
+ val nestedCtx = ctx.fresh.setExploreTyperState
isCompatible(normalize(tp, pt)(nestedCtx), pt)(nestedCtx)
}
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 7c301a7f1..0ba53f8c0 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -587,7 +587,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
assignType(cpy.CaseDef(tree, pat, guard1, body1), body1)
}
val doCase: () => CaseDef =
- () => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.withNewScope)
+ () => caseRest(typedPattern(tree.pat, selType))(ctx.fresh.clearScope)
(doCase /: gadtSyms)((op, tsym) => tsym.withGADTFlexType(op))()
}
@@ -835,7 +835,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val pid1 = typedExpr(tree.pid, AnySelectionProto)
val pkg = pid1.symbol
val packageContext =
- if (pkg is Package) ctx.fresh.withOwner(pkg.moduleClass).withTree(tree)
+ if (pkg is Package) ctx.fresh.setOwner(pkg.moduleClass).setTree(tree)
else {
ctx.error(i"$pkg is not a packge", tree.pos)
ctx
@@ -872,8 +872,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
NoSymbol
}
def localContext = {
- val freshCtx = ctx.fresh.withTree(xtree)
- if (sym.exists) freshCtx.withOwner(sym)
+ val freshCtx = ctx.fresh.setTree(xtree)
+ if (sym.exists) freshCtx.setOwner(sym)
else freshCtx // can happen for self defs
}
@@ -884,13 +884,13 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case tree: untpd.Bind => typedBind(tree, pt)
case tree: untpd.ValDef =>
if (tree.isEmpty) tpd.EmptyValDef
- else typedValDef(tree, sym)(localContext.withNewScope)
+ else typedValDef(tree, sym)(localContext.clearScope)
case tree: untpd.DefDef =>
val typer1 = nestedTyper.remove(sym).get
- typer1.typedDefDef(tree, sym)(localContext.withTyper(typer1))
+ typer1.typedDefDef(tree, sym)(localContext.setTyper(typer1))
case tree: untpd.TypeDef =>
if (tree.isClassDef) typedClassDef(tree, sym.asClass)(localContext)
- else typedTypeDef(tree, sym)(localContext.withNewScope)
+ else typedTypeDef(tree, sym)(localContext.clearScope)
case _ => typedUnadapted(desugar(tree), pt)
}
@@ -904,7 +904,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case tree: untpd.Typed => typedTyped(tree, pt)
case tree: untpd.NamedArg => typedNamedArg(tree, pt)
case tree: untpd.Assign => typedAssign(tree, pt)
- case tree: untpd.Block => typedBlock(desugar.block(tree), pt)(ctx.fresh.withNewScope)
+ case tree: untpd.Block => typedBlock(desugar.block(tree), pt)(ctx.fresh.clearScope)
case tree: untpd.If => typedIf(tree, pt)
case tree: untpd.Function => typedFunction(tree, pt)
case tree: untpd.Closure => typedClosure(tree, pt)
@@ -970,7 +970,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
case Thicket(stats) :: rest =>
traverse(stats ++ rest)
case stat :: rest =>
- val nestedCtx = if (exprOwner == ctx.owner) ctx else ctx.fresh.withOwner(exprOwner)
+ val nestedCtx = if (exprOwner == ctx.owner) ctx else ctx.fresh.setOwner(exprOwner)
buf += typed(stat)(nestedCtx)
traverse(rest)
case nil =>
@@ -987,7 +987,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
typed(tree, pt)(ctx addMode Mode.Pattern)
def tryEither[T](op: Context => T)(fallBack: (T, TyperState) => T)(implicit ctx: Context) = {
- val nestedCtx = ctx.fresh.withNewTyperState
+ val nestedCtx = ctx.fresh.clearTyperState
val result = op(nestedCtx)
if (nestedCtx.reporter.hasErrors)
fallBack(result, nestedCtx.typerState)