Skip to content

Commit

Permalink
SI-6362 & SI-5924 removes caches in the macro API
Browse files Browse the repository at this point in the history
As recent experience shows, it's hardly possible to provide a global cache
that persists between compilation runs: http://groups.google.com/group/scala-ide-user/browse_thread/thread/b1cab5588ff21f7f.
Therefore I think we need to remove Context.globalCache.

Speaking of a per-run cache, it looks like Context.cache can be
to a certain extent emulated with attachments. Otherwise, one could write
a JVM-wide static cache weakly indexed by compilation run instances
(that are available via c.currentRun).

For now I think we need to remove both caches. If macro writers really need
that functionality, we could come up with a well-thought API later.
  • Loading branch information
xeno-by committed Sep 14, 2012
1 parent ba3a9e0 commit e6176af
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 26 deletions.
Expand Up @@ -33,8 +33,4 @@ trait Infrastructure {
}

val currentMacro: Symbol = expandee.symbol

val globalCache: scala.collection.mutable.Map[Any, Any] = universe.analyzer.globalMacroCache

val cache: scala.collection.mutable.Map[Any, Any] = universe.analyzer.perRunMacroCache.getOrElseUpdate(currentMacro, collection.mutable.Map[Any, Any]())
}
3 changes: 0 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/Macros.scala
Expand Up @@ -49,9 +49,6 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces {
import MacrosStats._
def globalSettings = global.settings

val globalMacroCache = collection.mutable.Map[Any, Any]()
val perRunMacroCache = perRunCaches.newMap[Symbol, collection.mutable.Map[Any, Any]]

/** `MacroImplBinding` and its companion module are responsible for
* serialization/deserialization of macro def -> impl bindings.
*
Expand Down
19 changes: 0 additions & 19 deletions src/reflect/scala/reflect/macros/Infrastructure.scala
Expand Up @@ -77,23 +77,4 @@ trait Infrastructure {
/** Returns a macro definition which triggered this macro expansion.
*/
val currentMacro: Symbol

// todo. redo caches as discussed on Reflecting Meeting 2012/03/29
// https://docs.google.com/document/d/1oUZGQpdt2qwioTlJcSt8ZFQwVLTvpxn8xa67P8OGVpU/edit

/** A cache shared by all invocations of all macros across all compilation runs.
*
* Needs to be used with extreme care, since memory leaks here will swiftly crash the presentation compiler.
* For example, Scala IDE typically launches a compiler run on every edit action so there might be hundreds of runs per minute.
*/
val globalCache: scala.collection.mutable.Map[Any, Any]

/** A cache shared by all invocations of the same macro within a single compilation run.
*
* This cache is cleared automatically after a compilation run is completed or abandoned.
* It is also specific to a particular macro definition.
*
* To share data between different macros and/or different compilation runs, use ``globalCache''.
*/
val cache: scala.collection.mutable.Map[Any, Any]
}

0 comments on commit e6176af

Please sign in to comment.