From 1b7fa21a83a5bb400acb544e1fdcb026c25f4e10 Mon Sep 17 00:00:00 2001 From: Dmitry Savvinov Date: Mon, 12 Aug 2019 15:56:34 +0300 Subject: [PATCH] Minor. Add comments to creation of DelegatingBindingTrace --- .../kotlin/idea/caches/resolve/PerFileAnalysisCache.kt | 10 ++++++++++ .../kotlin/idea/project/ResolveElementCache.kt | 7 ++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/PerFileAnalysisCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/PerFileAnalysisCache.kt index ab9ed91e05b..dbeacd938e9 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/PerFileAnalysisCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/caches/resolve/PerFileAnalysisCache.kt @@ -180,6 +180,16 @@ private object KotlinResolveDataProvider { return AnalysisResult.success(bindingContext, moduleDescriptor) } + /* + Note that currently we *have* to re-create LazyTopDownAnalyzer with custom trace in order to disallow resolution of + bodies in top-level trace (trace from DI-container). + Resolving bodies in top-level trace may lead to memory leaks and incorrect resolution, because top-level + trace isn't invalidated on in-block modifications (while body resolution surely does) + + Also note that for function bodies, we'll create DelegatingBindingTrace in ResolveElementCache anyways + (see 'functionAdditionalResolve'). However, this trace is still needed, because we have other + codepaths for other KtDeclarationWithBodies (like property accessors/secondary constructors/class initializers) + */ val trace = DelegatingBindingTrace( resolveSession.bindingContext, "Trace for resolution of " + analyzableElement, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt index f1b2069df6d..8892a2fe463 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/project/ResolveElementCache.kt @@ -720,7 +720,12 @@ class ResolveElementCache( ).get() } - // All additional resolve should be done to separate trace + /* + Note that currently we *have* to re-create container with custom trace in order to disallow resolution of + bodies in top-level trace (trace from DI-container). + Resolving bodies in top-level trace may lead to memory leaks and incorrect resolution, because top-level + trace isn't invalidated on in-block modifications (while body resolution surely does) + */ private fun createDelegatingTrace(resolveElement: KtElement, filter: BindingTraceFilter): BindingTrace { return resolveSession.storageManager.createSafeTrace( DelegatingBindingTrace(