From c4aa3c058904912ba1b5696b2aaa4d9234dc5c79 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Wed, 12 Nov 2014 17:12:44 +0100 Subject: Avoid forcing infos of some symbols in InfoTransforms Provides the "mayChange" hook to exclude symbols from being completed prior to a transformInfo. --- src/dotty/tools/dotc/core/DenotTransformers.scala | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/dotty/tools/dotc/core/DenotTransformers.scala') diff --git a/src/dotty/tools/dotc/core/DenotTransformers.scala b/src/dotty/tools/dotc/core/DenotTransformers.scala index 0e31d87e6..02d27ea33 100644 --- a/src/dotty/tools/dotc/core/DenotTransformers.scala +++ b/src/dotty/tools/dotc/core/DenotTransformers.scala @@ -38,13 +38,23 @@ object DenotTransformers { def transformInfo(tp: Type, sym: Symbol)(implicit ctx: Context): Type def transform(ref: SingleDenotation)(implicit ctx: Context): SingleDenotation = { - val info1 = transformInfo(ref.info, ref.symbol) - if (info1 eq ref.info) ref - else ref match { - case ref: SymDenotation => ref.copySymDenotation(info = info1) - case _ => ref.derivedSingleDenotation(ref.symbol, info1) + val sym = ref.symbol + if (sym.exists && !mayChange(sym)) ref + else { + val info1 = transformInfo(ref.info, ref.symbol) + if (info1 eq ref.info) ref + else ref match { + case ref: SymDenotation => ref.copySymDenotation(info = info1) + case _ => ref.derivedSingleDenotation(ref.symbol, info1) + } } } + + /** Denotations with a symbol where `mayChange` is false are guaranteed to be + * unaffected by this transform, so `transformInfo` need not be run. This + * can save time, and more importantly, can help avoid forcing symbol completers. + */ + protected def mayChange(sym: Symbol)(implicit ctx: Context): Boolean = true } /** A transformer that only transforms SymDenotations */ -- cgit v1.2.3