Allow slice rewrite in trace when in IDE
This commit is contained in:
+1
-1
@@ -59,7 +59,7 @@ public final class JvmSerializationBindings {
|
|||||||
BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class);
|
BasicWritableSlice.initSliceDebugNames(JvmSerializationBindings.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final MutableSlicedMap map = SlicedMapImpl.create();
|
private final MutableSlicedMap map = new SlicedMapImpl(false);
|
||||||
|
|
||||||
public <K, V> void put(@NotNull SerializationMappingSlice<K, V> slice, @NotNull K key, @NotNull V value) {
|
public <K, V> void put(@NotNull SerializationMappingSlice<K, V> slice, @NotNull K key, @NotNull V value) {
|
||||||
map.put(slice, key, value);
|
map.put(slice, key, value);
|
||||||
|
|||||||
@@ -79,12 +79,16 @@ public class BindingTraceContext implements BindingTrace {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public BindingTraceContext() {
|
public BindingTraceContext() {
|
||||||
this(BindingTraceFilter.Companion.getACCEPT_ALL());
|
this(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BindingTraceContext(BindingTraceFilter filter) {
|
public BindingTraceContext(boolean allowSliceRewrite) {
|
||||||
|
this(BindingTraceFilter.Companion.getACCEPT_ALL(), allowSliceRewrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BindingTraceContext(BindingTraceFilter filter, boolean allowSliceRewrite) {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
this(TRACK_REWRITES ? new TrackingSlicedMap(TRACK_WITH_STACK_TRACES) : SlicedMapImpl.create(), filter);
|
this(TRACK_REWRITES && !allowSliceRewrite ? new TrackingSlicedMap(TRACK_WITH_STACK_TRACES) : new SlicedMapImpl(allowSliceRewrite), filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve
|
package org.jetbrains.kotlin.resolve
|
||||||
|
|
||||||
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
|
||||||
import com.intellij.openapi.project.Project
|
|
||||||
import com.intellij.openapi.components.ServiceManager
|
import com.intellij.openapi.components.ServiceManager
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||||
|
import org.jetbrains.kotlin.resolve.lazy.KotlinCodeAnalyzer
|
||||||
|
|
||||||
interface CodeAnalyzerInitializer {
|
interface CodeAnalyzerInitializer {
|
||||||
fun initialize(trace: BindingTrace, module: ModuleDescriptor, codeAnalyzer: KotlinCodeAnalyzer)
|
fun initialize(trace: BindingTrace, module: ModuleDescriptor, codeAnalyzer: KotlinCodeAnalyzer)
|
||||||
@@ -36,5 +36,5 @@ class DummyCodeAnalyzerInitializer: CodeAnalyzerInitializer {
|
|||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createTrace(): BindingTrace = BindingTraceContext()
|
override fun createTrace(): BindingTrace = BindingTraceContext(true)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,11 +26,19 @@ import org.jetbrains.kotlin.types.KotlinType
|
|||||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
|
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
|
||||||
import org.jetbrains.kotlin.util.slicedMap.*
|
import org.jetbrains.kotlin.util.slicedMap.*
|
||||||
|
|
||||||
open class DelegatingBindingTrace(private val parentContext: BindingContext,
|
open class DelegatingBindingTrace(
|
||||||
private val name: String,
|
private val parentContext: BindingContext,
|
||||||
withParentDiagnostics: Boolean = true,
|
private val name: String,
|
||||||
private val filter: BindingTraceFilter = BindingTraceFilter.ACCEPT_ALL) : BindingTrace {
|
withParentDiagnostics: Boolean = true,
|
||||||
private val map = if (BindingTraceContext.TRACK_REWRITES) TrackingSlicedMap(BindingTraceContext.TRACK_WITH_STACK_TRACES) else SlicedMapImpl.create()
|
private val filter: BindingTraceFilter = BindingTraceFilter.ACCEPT_ALL,
|
||||||
|
allowSliceRewrite: Boolean = false
|
||||||
|
) : BindingTrace {
|
||||||
|
|
||||||
|
private val map = if (BindingTraceContext.TRACK_REWRITES && !allowSliceRewrite)
|
||||||
|
TrackingSlicedMap(BindingTraceContext.TRACK_WITH_STACK_TRACES)
|
||||||
|
else
|
||||||
|
SlicedMapImpl(allowSliceRewrite)
|
||||||
|
|
||||||
private val mutableDiagnostics: MutableDiagnosticsWithSuppression?
|
private val mutableDiagnostics: MutableDiagnosticsWithSuppression?
|
||||||
|
|
||||||
private inner class MyBindingContext : BindingContext {
|
private inner class MyBindingContext : BindingContext {
|
||||||
@@ -72,10 +80,12 @@ open class DelegatingBindingTrace(private val parentContext: BindingContext,
|
|||||||
constructor(parentContext: BindingContext,
|
constructor(parentContext: BindingContext,
|
||||||
debugName: String,
|
debugName: String,
|
||||||
resolutionSubjectForMessage: Any?,
|
resolutionSubjectForMessage: Any?,
|
||||||
filter: BindingTraceFilter = BindingTraceFilter.ACCEPT_ALL)
|
filter: BindingTraceFilter = BindingTraceFilter.ACCEPT_ALL,
|
||||||
: this(parentContext,
|
allowSliceRewrite: Boolean = false
|
||||||
AnalyzingUtils.formDebugNameForBindingTrace(debugName, resolutionSubjectForMessage),
|
) : this(parentContext,
|
||||||
filter = filter)
|
AnalyzingUtils.formDebugNameForBindingTrace(debugName, resolutionSubjectForMessage),
|
||||||
|
filter = filter,
|
||||||
|
allowSliceRewrite = allowSliceRewrite)
|
||||||
|
|
||||||
override fun getBindingContext(): BindingContext = bindingContext
|
override fun getBindingContext(): BindingContext = bindingContext
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public class TemporaryBindingTrace extends DelegatingBindingTrace {
|
|||||||
protected final BindingTrace trace;
|
protected final BindingTrace trace;
|
||||||
|
|
||||||
protected TemporaryBindingTrace(@NotNull BindingTrace trace, String debugName, BindingTraceFilter filter) {
|
protected TemporaryBindingTrace(@NotNull BindingTrace trace, String debugName, BindingTraceFilter filter) {
|
||||||
super(trace.getBindingContext(), debugName, true, filter);
|
super(trace.getBindingContext(), debugName, true, filter, false);
|
||||||
this.trace = trace;
|
this.trace = trace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -587,7 +587,7 @@ public class CallResolver {
|
|||||||
if (CallResolverUtilKt.isInvokeCallOnVariable(call)) return;
|
if (CallResolverUtilKt.isInvokeCallOnVariable(call)) return;
|
||||||
|
|
||||||
DelegatingBindingTrace deltasTraceToCacheResolve = new DelegatingBindingTrace(
|
DelegatingBindingTrace deltasTraceToCacheResolve = new DelegatingBindingTrace(
|
||||||
BindingContext.EMPTY, "delta trace for caching resolve of", context.call, BindingTraceFilter.Companion.getACCEPT_ALL());
|
BindingContext.EMPTY, "delta trace for caching resolve of", context.call, BindingTraceFilter.Companion.getACCEPT_ALL(), false);
|
||||||
traceToResolveCall.addOwnDataTo(deltasTraceToCacheResolve);
|
traceToResolveCall.addOwnDataTo(deltasTraceToCacheResolve);
|
||||||
|
|
||||||
context.resolutionResultsCache.record(call, results, context, tracing, deltasTraceToCacheResolve);
|
context.resolutionResultsCache.record(call, results, context, tracing, deltasTraceToCacheResolve);
|
||||||
|
|||||||
@@ -31,13 +31,14 @@ import java.util.Map;
|
|||||||
|
|
||||||
public class SlicedMapImpl implements MutableSlicedMap {
|
public class SlicedMapImpl implements MutableSlicedMap {
|
||||||
|
|
||||||
public static SlicedMapImpl create() {
|
private final boolean alwaysAllowRewrite;
|
||||||
return new SlicedMapImpl();
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Map<Object, KeyFMap> map = new THashMap<>(0);
|
private final Map<Object, KeyFMap> map = new THashMap<>(0);
|
||||||
private Multimap<WritableSlice<?, ?>, Object> collectiveSliceKeys = null;
|
private Multimap<WritableSlice<?, ?>, Object> collectiveSliceKeys = null;
|
||||||
|
|
||||||
|
public SlicedMapImpl(boolean alwaysAllowRewrite) {
|
||||||
|
this.alwaysAllowRewrite = alwaysAllowRewrite;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <K, V> void put(WritableSlice<K, V> slice, K key, V value) {
|
public <K, V> void put(WritableSlice<K, V> slice, K key, V value) {
|
||||||
if (!slice.check(key, value)) {
|
if (!slice.check(key, value)) {
|
||||||
@@ -52,7 +53,7 @@ public class SlicedMapImpl implements MutableSlicedMap {
|
|||||||
Key<V> sliceKey = slice.getKey();
|
Key<V> sliceKey = slice.getKey();
|
||||||
|
|
||||||
RewritePolicy rewritePolicy = slice.getRewritePolicy();
|
RewritePolicy rewritePolicy = slice.getRewritePolicy();
|
||||||
if (rewritePolicy.rewriteProcessingNeeded(key)) {
|
if (!alwaysAllowRewrite && rewritePolicy.rewriteProcessingNeeded(key)) {
|
||||||
V oldValue = holder.get(sliceKey);
|
V oldValue = holder.get(sliceKey);
|
||||||
if (oldValue != null) {
|
if (oldValue != null) {
|
||||||
//noinspection unchecked
|
//noinspection unchecked
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class TrackingSlicedMap extends SlicedMapImpl {
|
|||||||
private final boolean trackWithStackTraces;
|
private final boolean trackWithStackTraces;
|
||||||
|
|
||||||
public TrackingSlicedMap(boolean trackWithStackTraces) {
|
public TrackingSlicedMap(boolean trackWithStackTraces) {
|
||||||
|
super(false);
|
||||||
this.trackWithStackTraces = trackWithStackTraces;
|
this.trackWithStackTraces = trackWithStackTraces;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -159,7 +159,7 @@ private object KotlinResolveDataProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val resolveSession = componentProvider.get<ResolveSession>()
|
val resolveSession = componentProvider.get<ResolveSession>()
|
||||||
val trace = DelegatingBindingTrace(resolveSession.bindingContext, "Trace for resolution of " + analyzableElement)
|
val trace = DelegatingBindingTrace(resolveSession.bindingContext, "Trace for resolution of " + analyzableElement, allowSliceRewrite = true)
|
||||||
|
|
||||||
val targetPlatform = TargetPlatformDetector.getPlatform(analyzableElement.containingKtFile)
|
val targetPlatform = TargetPlatformDetector.getPlatform(analyzableElement.containingKtFile)
|
||||||
|
|
||||||
|
|||||||
@@ -344,7 +344,7 @@ class ResolveElementCache(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val controlFlowTrace = DelegatingBindingTrace(trace.bindingContext, "Element control flow resolve", resolveElement)
|
val controlFlowTrace = DelegatingBindingTrace(trace.bindingContext, "Element control flow resolve", resolveElement, allowSliceRewrite = true)
|
||||||
ControlFlowInformationProvider(resolveElement, controlFlowTrace, resolveElement.languageVersionSettings).checkDeclaration()
|
ControlFlowInformationProvider(resolveElement, controlFlowTrace, resolveElement.languageVersionSettings).checkDeclaration()
|
||||||
controlFlowTrace.addOwnDataTo(trace, null, false)
|
controlFlowTrace.addOwnDataTo(trace, null, false)
|
||||||
|
|
||||||
@@ -595,7 +595,7 @@ class ResolveElementCache(
|
|||||||
// All additional resolve should be done to separate trace
|
// All additional resolve should be done to separate trace
|
||||||
private fun createDelegatingTrace(resolveElement: KtElement, filter: BindingTraceFilter): BindingTrace {
|
private fun createDelegatingTrace(resolveElement: KtElement, filter: BindingTraceFilter): BindingTrace {
|
||||||
return resolveSession.storageManager.createSafeTrace(
|
return resolveSession.storageManager.createSafeTrace(
|
||||||
DelegatingBindingTrace(resolveSession.bindingContext, "trace to resolve element", resolveElement, filter))
|
DelegatingBindingTrace(resolveSession.bindingContext, "trace to resolve element", resolveElement, filter, allowSliceRewrite = true))
|
||||||
}
|
}
|
||||||
|
|
||||||
private class BodyResolveContextForLazy(
|
private class BodyResolveContextForLazy(
|
||||||
|
|||||||
Reference in New Issue
Block a user