diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-31 14:53:44 +0200 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-03-31 14:53:44 +0200 |
commit | 318db7dc616a659687d95380efa16159cfaeb984 (patch) | |
tree | fe1b2805b10ba7381af61b0ce70d47adfa134253 /src/dotty/tools/dotc/core | |
parent | d173cc048ebdbff30f6537f207118fc5717b8787 (diff) | |
download | dotty-318db7dc616a659687d95380efa16159cfaeb984.tar.gz dotty-318db7dc616a659687d95380efa16159cfaeb984.tar.bz2 dotty-318db7dc616a659687d95380efa16159cfaeb984.zip |
Memoizing Context#withPhase
withPhase operations in contexts are now memoized.
Conflicts:
src/dotty/tools/dotc/core/Contexts.scala
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r-- | src/dotty/tools/dotc/core/Contexts.scala | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index 4ccc9be73..b0214a631 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -181,6 +181,30 @@ object Contexts { protected def searchHistory_= (searchHistory: SearchHistory) = _searchHistory = searchHistory def searchHistory: SearchHistory = _searchHistory + private var phasedCtx: Context = _ + private var phasedCtxs: Array[Context] = _ + + + /** This context at given phase. + * This method will always return a phase period equal to phaseId, thus will never return squashed phases + */ + final def withPhase(phaseId: PhaseId): Context = { + if (this.phaseId == phaseId) this + else if (phasedCtx.phaseId == phaseId) phasedCtx + else if (phasedCtxs != null && phasedCtxs(phaseId) != null) phasedCtxs(phaseId) + else { + val ctx1 = fresh.setPhase(phaseId) + if (phasedCtx eq this) phasedCtx = ctx1 + else { + if (phasedCtxs == null) phasedCtxs = new Array[Context](base.phases.length) + phasedCtxs(phaseId) = ctx1 + } + ctx1 + } + } + + final def withPhase(phase: Phase): Context = + withPhase(phase.id) /** If -Ydebug is on, the top of the stack trace where this context * was created, otherwise `null`. */ @@ -266,16 +290,16 @@ object Contexts { } */ - /** A fresh clone of this context. */ - def fresh: FreshContext = { - val newctx: Context = super.clone.asInstanceOf[FreshContext] - newctx.outer = this - newctx.implicitsCache = null - newctx.setCreationTrace() - // Dotty deviation: Scala2x allows access to private members implicitCache and setCreationTrace - // even from a subclass prefix. Dotty (and Java) do not. It's confirmed as a bug in Scala2x. - newctx.asInstanceOf[FreshContext] + protected def init(outer: Context): this.type = { + this.outer = outer + this.implicitsCache = null + this.phasedCtx = this + this.phasedCtxs = null + setCreationTrace() + this } + /** A fresh clone of this context. */ + def fresh: FreshContext = clone.asInstanceOf[FreshContext].init(this) final def withOwner(owner: Symbol): Context = if (owner ne this.owner) fresh.setOwner(owner) else this @@ -283,15 +307,6 @@ object Contexts { final def withMode(mode: Mode): Context = if (mode != this.mode) fresh.setMode(mode) else this - /** - * This method will always return a phase period equal to phaseId, thus will never return squashed phases - */ - final def withPhase(phaseId: PhaseId): Context = - if (this.phaseId == phaseId) this else fresh.setPhase(phaseId) - final def withPhase(phase: Phase): Context = - if (this.period == phase.period) this else fresh.setPhase(phase) - - final def addMode(mode: Mode): Context = withMode(this.mode | mode) final def maskMode(mode: Mode): Context = withMode(this.mode & mode) final def retractMode(mode: Mode): Context = withMode(this.mode &~ mode) |