Skip to content

Commit 25e0986

Browse files
committed
Fleshed out printers.
1 parent fec107c commit 25e0986

File tree

2 files changed

+374
-55
lines changed

2 files changed

+374
-55
lines changed

src/dotty/tools/dotc/core/Contexts.scala

+23
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ import config.{Settings, Platform, JavaPlatform}
1616

1717
object Contexts {
1818

19+
/** A context is passed basically everywhere in dotc.
20+
* This is convenient but carries the risk of captured contexts in
21+
* objects that turn into space leaks. To combat this risk, here are some
22+
* conventions to follow:
23+
*
24+
* - Never let an implicit context be an argument of a class whose instances
25+
* live longer than the context.
26+
* - Classes that need contexts for their initialization take an explicit parameter
27+
* named `initctx`. They pass initctx to all positions where it is needed
28+
* (and these positions should all be part of the intialization sequence of the class).
29+
* - Classes that need contexts that survive initialization are passed
30+
* a "condensed context", typically named `cctx` instead. Consensed contexts
31+
* just add some basic information to the context base without the
32+
* risk of capturing complete trees.
33+
* - To make sure these rules are kept, it would be good to do a sanity
34+
* check using bytecode inspection with javap or scalap: Keep track
35+
* of all class fields of type context; allow them only in whitelisted
36+
* classes (which should be short-lived).
37+
*/
1938
abstract class Context extends Periods
2039
with Substituters
2140
with TypeOps
@@ -182,6 +201,10 @@ object Contexts {
182201
private[core] val pendingVolatiles = new mutable.HashSet[Type]
183202
}
184203

204+
object Context {
205+
implicit def toPrinter(ctx: Context) = ctx.printer(ctx)
206+
}
207+
185208
implicit def ctxToBase(ctx: Context): ContextBase = ctx.base
186209

187210
/** Initial size of superId table */

0 commit comments

Comments
 (0)