From 465ea96afb46e29fb523dad884f0ba860eeea6ff Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 Oct 2015 17:07:34 +0100 Subject: [PATCH 1/4] add out/ to .gitignore It messes up git operations with out/.keep out of date. --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 95d95ca1158a..44b3bc64b29b 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ # sbt specific dist/* target/ +out/ lib_managed/ src_managed/ project/boot/ From f6e454ba8ba2f1183177e1f69788bf9610512c3f Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 Oct 2015 17:07:51 +0100 Subject: [PATCH 2/4] Fix #877 Use freshName to name evidence parameters. --- src/dotty/tools/dotc/ast/Desugar.scala | 2 +- tests/pos/i877.scala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i877.scala diff --git a/src/dotty/tools/dotc/ast/Desugar.scala b/src/dotty/tools/dotc/ast/Desugar.scala index d1f101283e05..621ac8ece35a 100644 --- a/src/dotty/tools/dotc/ast/Desugar.scala +++ b/src/dotty/tools/dotc/ast/Desugar.scala @@ -132,7 +132,7 @@ object desugar { case tparam @ TypeDef(_, ContextBounds(tbounds, cxbounds)) => for (cxbound <- cxbounds) { val paramFlags: FlagSet = if (isPrimaryConstructor) PrivateLocalParamAccessor else Param - val epname = (nme.EVIDENCE_PARAM_PREFIX.toString + epbuf.length).toTermName + val epname = ctx.freshName(nme.EVIDENCE_PARAM_PREFIX).toTermName epbuf += ValDef(epname, cxbound, EmptyTree).withFlags(paramFlags | Implicit) } cpy.TypeDef(tparam)(rhs = tbounds) diff --git a/tests/pos/i877.scala b/tests/pos/i877.scala new file mode 100644 index 000000000000..45a71ae0d7c3 --- /dev/null +++ b/tests/pos/i877.scala @@ -0,0 +1,11 @@ +class First[A] +class Second[A] + +class Foo { + def foo[A: First] = { + def bar[B: Second] = { + val fst: First[A] = implicitly[First[A]] + val snd: Second[B] = implicitly[Second[B]] + } + } +} From 64247c1935f13645a12f21238c73727ebb607134 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Fri, 30 Oct 2015 23:19:59 +0100 Subject: [PATCH 3/4] Make a new fresh name creator for each unit Needed to make builds deterministic. --- src/dotty/tools/dotc/Compiler.scala | 9 ++++----- src/dotty/tools/dotc/core/Contexts.scala | 16 ++++++++++------ src/dotty/tools/dotc/typer/FrontEnd.scala | 4 +++- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/dotty/tools/dotc/Compiler.scala b/src/dotty/tools/dotc/Compiler.scala index a36743b59a03..bf3dbb232bc3 100644 --- a/src/dotty/tools/dotc/Compiler.scala +++ b/src/dotty/tools/dotc/Compiler.scala @@ -9,11 +9,10 @@ import Scopes._ import typer.{FrontEnd, Typer, Mode, ImportInfo, RefChecks} import reporting.{Reporter, ConsoleReporter} import Phases.Phase -import dotty.tools.dotc.transform._ -import dotty.tools.dotc.transform.TreeTransforms.{TreeTransform, TreeTransformer} -import dotty.tools.dotc.core.DenotTransformers.DenotTransformer -import dotty.tools.dotc.core.Denotations.SingleDenotation - +import transform._ +import transform.TreeTransforms.{TreeTransform, TreeTransformer} +import core.DenotTransformers.DenotTransformer +import core.Denotations.SingleDenotation import dotty.tools.backend.jvm.{LabelDefs, GenBCode} diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index f9d64b2cc56f..dcdfedca5336 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -153,6 +153,14 @@ object Contexts { protected def gadt_=(gadt: GADTMap) = _gadt = gadt def gadt: GADTMap = _gadt + /**The current fresh name creator */ + private[this] var _freshNames: FreshNameCreator = _ + protected def freshNames_=(freshNames: FreshNameCreator) = _freshNames = freshNames + def freshNames: FreshNameCreator = _freshNames + + def freshName(prefix: String = ""): String = freshNames.newName(prefix) + def freshName(prefix: Name): String = freshName(prefix.toString) + /** A map in which more contextual properties can be stored */ private var _moreProperties: Map[String, Any] = _ protected def moreProperties_=(moreProperties: Map[String, Any]) = _moreProperties = moreProperties @@ -423,6 +431,7 @@ object Contexts { def setDiagnostics(diagnostics: Option[StringBuilder]): this.type = { this.diagnostics = diagnostics; this } def setTypeComparerFn(tcfn: Context => TypeComparer): this.type = { this.typeComparer = tcfn(this); this } def setSearchHistory(searchHistory: SearchHistory): this.type = { this.searchHistory = searchHistory; this } + def setFreshNames(freshNames: FreshNameCreator): this.type = { this.freshNames = freshNames; this } def setMoreProperties(moreProperties: Map[String, Any]): this.type = { this.moreProperties = moreProperties; this } def setProperty(prop: (String, Any)): this.type = setMoreProperties(moreProperties + prop) @@ -468,6 +477,7 @@ object Contexts { typeAssigner = TypeAssigner runInfo = new RunInfo(this) diagnostics = None + freshNames = new FreshNameCreator.Default moreProperties = Map.empty typeComparer = new TypeComparer(this) searchHistory = new SearchHistory(0, Map()) @@ -498,12 +508,6 @@ object Contexts { /** The platform */ val platform: Platform = new JavaPlatform - /** The standard fresh name creator */ - val freshNames = new FreshNameCreator.Default - - def freshName(prefix: String = ""): String = freshNames.newName(prefix) - def freshName(prefix: Name): String = freshName(prefix.toString) - /** The loader that loads the members of _root_ */ def rootLoader(root: TermSymbol)(implicit ctx: Context): SymbolLoader = platform.rootLoader(root) diff --git a/src/dotty/tools/dotc/typer/FrontEnd.scala b/src/dotty/tools/dotc/typer/FrontEnd.scala index f417448bda69..01a587e5a019 100644 --- a/src/dotty/tools/dotc/typer/FrontEnd.scala +++ b/src/dotty/tools/dotc/typer/FrontEnd.scala @@ -9,6 +9,7 @@ import parsing.Parsers.Parser import config.Printers._ import util.Stats._ import scala.util.control.NonFatal +import util.FreshNameCreator class FrontEnd extends Phase { @@ -46,7 +47,8 @@ class FrontEnd extends Phase { } override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = { - val unitContexts = units map (unit => ctx.fresh.setCompilationUnit(unit)) + val unitContexts = for (unit <- units) yield + ctx.fresh.setCompilationUnit(unit).setFreshNames(new FreshNameCreator.Default) unitContexts foreach (parse(_)) record("parsedTrees", ast.Trees.ntrees) unitContexts foreach (enterSyms(_)) From 970a2bdc6c3ea7740e86217e1f30adb998457db9 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sat, 31 Oct 2015 13:08:25 +0100 Subject: [PATCH 4/4] add out/ to .gitignore It messes up git operations with out/.keep out of date. (reverted from commit 465ea96afb46e29fb523dad884f0ba860eeea6ff) --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 44b3bc64b29b..95d95ca1158a 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ # sbt specific dist/* target/ -out/ lib_managed/ src_managed/ project/boot/