Temporary use special container mapping logic for IR backend

This commit is contained in:
Mikhael Bogdanov
2018-08-08 15:55:57 +03:00
parent 813e1ffa39
commit 6b5b9fbde4
9 changed files with 74 additions and 26 deletions
@@ -17,7 +17,8 @@ class KotlinToJvmSignatureMapperImpl : KotlinToJvmSignatureMapper {
// We use empty BindingContext, because it is only used by KotlinTypeMapper for purposes irrelevant to the needs of this class
private val typeMapper = KotlinTypeMapper(
BindingContext.EMPTY, ClassBuilderMode.LIGHT_CLASSES,
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, false, KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT
IncompatibleClassTracker.DoNothing, JvmAbi.DEFAULT_MODULE_NAME, false, KotlinTypeMapper.RELEASE_COROUTINES_DEFAULT,
false
)
override fun mapToJvmMethodSignature(function: FunctionDescriptor) = typeMapper.mapAsmMethod(function)
@@ -48,12 +48,14 @@ class BuilderFactoryForDuplicateSignatureDiagnostics(
private val diagnostics: DiagnosticSink,
moduleName: String,
isReleaseCoroutines: Boolean,
shouldGenerate: (JvmDeclarationOrigin) -> Boolean
shouldGenerate: (JvmDeclarationOrigin) -> Boolean,
isIrBackend: Boolean
) : SignatureCollectingClassBuilderFactory(builderFactory, shouldGenerate) {
// Avoid errors when some classes are not loaded for some reason
private val typeMapper = KotlinTypeMapper(
bindingContext, ClassBuilderMode.LIGHT_CLASSES, IncompatibleClassTracker.DoNothing, moduleName, false, isReleaseCoroutines
bindingContext, ClassBuilderMode.LIGHT_CLASSES, IncompatibleClassTracker.DoNothing, moduleName, false, isReleaseCoroutines,
isIrBackend
)
private val reportDiagnosticsTasks = ArrayList<() -> Unit>()
@@ -181,13 +181,15 @@ class GenerationState private constructor(
filter = if (wantsDiagnostics) BindingTraceFilter.ACCEPT_ALL else BindingTraceFilter.NO_DIAGNOSTICS
)
val bindingContext: BindingContext = bindingTrace.bindingContext
private val isIrBackend = configuration.get(JVMConfigurationKeys.IR) ?: false
val typeMapper: KotlinTypeMapper = KotlinTypeMapper(
this.bindingContext,
classBuilderMode,
IncompatibleClassTrackerImpl(extraJvmDiagnosticsTrace),
this.moduleName,
isJvm8Target,
configuration.languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines)
configuration.languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines),
isIrBackend
)
val intrinsics: IntrinsicMethods = run {
val shouldUseConsistentEquals = languageVersionSettings.supportsFeature(LanguageFeature.ThrowNpeOnExplicitEqualsForBoxedNull) &&
@@ -251,7 +253,8 @@ class GenerationState private constructor(
BuilderFactoryForDuplicateSignatureDiagnostics(
it, this.bindingContext, diagnostics, this.moduleName,
isReleaseCoroutines = languageVersionSettings.supportsFeature(LanguageFeature.ReleaseCoroutines),
shouldGenerate = { !shouldOnlyCollectSignatures(it) }
shouldGenerate = { !shouldOnlyCollectSignatures(it) },
isIrBackend = isIrBackend
).apply { duplicateSignatureFactory = this }
},
{ BuilderFactoryForDuplicateClassNameDiagnostics(it, diagnostics) },
@@ -10,7 +10,6 @@ import com.intellij.psi.PsiElement;
import kotlin.Pair;
import kotlin.Unit;
import kotlin.collections.CollectionsKt;
import kotlin.reflect.KType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment;
@@ -87,6 +86,7 @@ public class KotlinTypeMapper {
private final String moduleName;
private final boolean isJvm8Target;
private final boolean isReleaseCoroutines;
private boolean isIrBackend;
private final TypeMappingConfiguration<Type> typeMappingConfiguration = new TypeMappingConfiguration<Type>() {
@NotNull
@@ -158,7 +158,7 @@ public class KotlinTypeMapper {
@NotNull String moduleName,
boolean isJvm8Target
) {
this(bindingContext, classBuilderMode, incompatibleClassTracker, moduleName, isJvm8Target, false);
this(bindingContext, classBuilderMode, incompatibleClassTracker, moduleName, isJvm8Target, false, false);
}
public KotlinTypeMapper(
@@ -167,7 +167,8 @@ public class KotlinTypeMapper {
@NotNull IncompatibleClassTracker incompatibleClassTracker,
@NotNull String moduleName,
boolean isJvm8Target,
boolean isReleaseCoroutines
boolean isReleaseCoroutines,
boolean isIrBackend
) {
this.bindingContext = bindingContext;
this.classBuilderMode = classBuilderMode;
@@ -175,6 +176,7 @@ public class KotlinTypeMapper {
this.moduleName = moduleName;
this.isJvm8Target = isJvm8Target;
this.isReleaseCoroutines = isReleaseCoroutines;
this.isIrBackend = isIrBackend;
}
public static final boolean RELEASE_COROUTINES_DEFAULT = false;
@@ -505,7 +507,8 @@ public class KotlinTypeMapper {
(ktType, asmType, typeMappingMode) -> {
writeGenericType(ktType, asmType, signatureVisitor, typeMappingMode);
return Unit.INSTANCE;
}
},
isIrBackend
);
}
@@ -541,7 +544,8 @@ public class KotlinTypeMapper {
) {
return TypeSignatureMappingKt.mapType(
kotlinType, AsmTypeFactory.INSTANCE, mode, staticTypeMappingConfiguration, null,
(ktType, asmType, typeMappingMode) -> Unit.INSTANCE
(ktType, asmType, typeMappingMode) -> Unit.INSTANCE,
false
);
}
@@ -1677,7 +1681,7 @@ public class KotlinTypeMapper {
if (recordedType != null) {
return recordedType.getInternalName();
}
return TypeSignatureMappingKt.computeInternalName(classDescriptor, typeMappingConfiguration);
return TypeSignatureMappingKt.computeInternalName(classDescriptor, typeMappingConfiguration, isIrBackend);
}
public static class InternalNameMapper {