Unify containing classes mapping for deserialized callable members.
This commit is contained in:
@@ -24,7 +24,7 @@ import org.jetbrains.kotlin.psi.JetFile
|
||||
public class CodegenFileClassesProvider(private val packageFacadesAsMultifileClasses: Boolean) : JvmFileClassesProvider {
|
||||
override public fun getFileClassInfo(file: JetFile): JvmFileClassInfo {
|
||||
val fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(file)
|
||||
if (packageFacadesAsMultifileClasses && !fileClassInfo.TEMP_isMultifileClass) {
|
||||
if (packageFacadesAsMultifileClasses && !fileClassInfo.withJvmMultifileClass) {
|
||||
return JvmFileClassUtil.getMultifilePackageFacadePartInfo(file)
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.jetbrains.kotlin.codegen;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import com.intellij.util.containers.HashMap;
|
||||
import com.intellij.util.containers.MultiMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
@@ -70,12 +69,12 @@ public class KotlinCodegenFacade {
|
||||
|
||||
JvmFileClassInfo fileClassInfo = state.getFileClassesProvider().getFileClassInfo(file);
|
||||
|
||||
if (fileClassInfo.getTEMP_isMultifileClass()) {
|
||||
if (fileClassInfo.getWithJvmMultifileClass()) {
|
||||
filesInMultifileClasses.putValue(fileClassInfo.getFacadeClassFqName(), file);
|
||||
}
|
||||
|
||||
if (state.getPackageFacadesAsMultifileClasses()) {
|
||||
if (!fileClassInfo.getTEMP_isMultifileClass()) {
|
||||
if (!fileClassInfo.getWithJvmMultifileClass()) {
|
||||
filesInMultifileClasses.putValue(PackageClassUtils.getPackageClassFqName(file.getPackageFqName()), file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,28 +35,25 @@ import org.jetbrains.kotlin.codegen.context.PackageContext;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializationBindings;
|
||||
import org.jetbrains.kotlin.codegen.serialization.JvmSerializerExtension;
|
||||
import org.jetbrains.kotlin.codegen.state.GenerationState;
|
||||
import org.jetbrains.kotlin.codegen.state.JetTypeMapper;
|
||||
import org.jetbrains.kotlin.config.IncrementalCompilation;
|
||||
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor;
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticUtils;
|
||||
import org.jetbrains.kotlin.fileClasses.FileClassesPackage;
|
||||
import org.jetbrains.kotlin.fileClasses.FileClasses;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassInfo;
|
||||
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil;
|
||||
import org.jetbrains.kotlin.load.java.JvmAbi;
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils;
|
||||
import org.jetbrains.kotlin.load.kotlin.PackageParts;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.IncrementalPackageFragmentProvider;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
|
||||
import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.MemberComparator;
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName;
|
||||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature;
|
||||
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
|
||||
import org.jetbrains.kotlin.resolve.scopes.JetScope;
|
||||
@@ -78,7 +75,6 @@ import static org.jetbrains.kotlin.codegen.AsmUtil.method;
|
||||
import static org.jetbrains.kotlin.load.kotlin.PackageClassUtils.getPackageClassFqName;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.K_PACKAGE_TYPE;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.getType;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.*;
|
||||
import static org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOrigin.NO_ORIGIN;
|
||||
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
|
||||
|
||||
@@ -114,7 +110,7 @@ public class PackageCodegen {
|
||||
JetFile sourceFile = getRepresentativePackageFile(files);
|
||||
|
||||
ClassBuilder v = PackageCodegen.this.state.getFactory().newVisitor(
|
||||
PackageFacade(packageFragment == null ? compiledPackageFragment : packageFragment),
|
||||
JvmDeclarationOriginKt.PackageFacade(packageFragment == null ? compiledPackageFragment : packageFragment),
|
||||
packageClassType, PackagePartClassUtils.getFilesWithCallables(files)
|
||||
);
|
||||
v.defineClass(sourceFile, V1_6,
|
||||
@@ -177,18 +173,20 @@ public class PackageCodegen {
|
||||
|
||||
private void generateDelegationsToPreviouslyCompiled(@NotNull @Mutable Map<CallableMemberDescriptor, Runnable> generateCallableMemberTasks) {
|
||||
for (final DeserializedCallableMemberDescriptor member : previouslyCompiledCallables) {
|
||||
final FqName delegateToFqName = JvmFileClassUtil.getPartFqNameForDeserializedCallable(member);
|
||||
|
||||
generateCallableMemberTasks.put(member, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
FieldOwnerContext context = getPackageFacadeContextForPreviouslyCompiled(delegateToFqName);
|
||||
JetTypeMapper.ContainingClassesInfo containingClasses = state.getTypeMapper().getContainingClassesForDeserializedCallable(member);
|
||||
|
||||
Type facadeType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(containingClasses.getFacadeClassId().asSingleFqName());
|
||||
Type partType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(containingClasses.getImplClassId().asSingleFqName());
|
||||
FieldOwnerContext context = state.getRootContext().intoPackageFacade(partType, compiledPackageFragment, facadeType);
|
||||
|
||||
MemberCodegen<?> memberCodegen = createCodegenForPartOfPackageFacade(context);
|
||||
|
||||
if (member instanceof DeserializedSimpleFunctionDescriptor) {
|
||||
DeserializedSimpleFunctionDescriptor function = (DeserializedSimpleFunctionDescriptor) member;
|
||||
memberCodegen.functionCodegen.generateMethod(OtherOrigin(function), function,
|
||||
memberCodegen.functionCodegen.generateMethod(JvmDeclarationOriginKt.OtherOrigin(function), function,
|
||||
new FunctionGenerationStrategy() {
|
||||
@Override
|
||||
public void generateBody(
|
||||
@@ -220,31 +218,6 @@ public class PackageCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private FieldOwnerContext getPackageFacadeContextForPreviouslyCompiled(@NotNull FqName delegateToFqName) {
|
||||
Type delegateToType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(delegateToFqName);
|
||||
String partInternalName = JvmClassName.byFqNameWithoutInnerClasses(delegateToFqName).getInternalName();
|
||||
TargetId targetId = state.getTargetId();
|
||||
assert targetId != null
|
||||
: "targetId is required for incremental compilation of " + packageClassType;
|
||||
IncrementalCompilationComponents incrementalCompilationComponents = state.getIncrementalCompilationComponents();
|
||||
assert incrementalCompilationComponents != null
|
||||
: "incrementalCompilationComponents is required for incremental compilation of " + packageClassType;
|
||||
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId);
|
||||
String facadeInternalName = incrementalCache.getMultifileFacade(partInternalName);
|
||||
|
||||
Type publicFacadeType;
|
||||
if (facadeInternalName != null) {
|
||||
FqName facadeFqName = JvmClassName.byInternalName(facadeInternalName).getFqNameForClassNameWithoutDollars();
|
||||
publicFacadeType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(facadeFqName);
|
||||
}
|
||||
else {
|
||||
publicFacadeType = delegateToType;
|
||||
}
|
||||
|
||||
return state.getRootContext().intoPackageFacade(delegateToType, compiledPackageFragment, publicFacadeType);
|
||||
}
|
||||
|
||||
public void generate(@NotNull CompilationErrorHandler errorHandler) {
|
||||
List<JvmSerializationBindings> bindings = new ArrayList<JvmSerializationBindings>(files.size() + 1);
|
||||
|
||||
@@ -337,7 +310,7 @@ public class PackageCodegen {
|
||||
) {
|
||||
JvmFileClassInfo fileClassInfo = state.getFileClassesProvider().getFileClassInfo(file);
|
||||
|
||||
if (fileClassInfo.getIsMultifileClass()) {
|
||||
if (fileClassInfo.getWithJvmMultifileClass()) {
|
||||
FqName partClassFqName = fileClassInfo.getFileClassFqName();
|
||||
Type delegateToType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(partClassFqName);
|
||||
Type publicFacadeType = AsmUtil.asmTypeByFqNameWithoutInnerClasses(fileClassInfo.getFacadeClassFqName());
|
||||
@@ -375,7 +348,7 @@ public class PackageCodegen {
|
||||
String name = fileClassType.getInternalName();
|
||||
packageParts.getParts().add(name.substring(name.lastIndexOf('/') + 1));
|
||||
|
||||
ClassBuilder builder = state.getFactory().newVisitor(PackagePart(file, packageFragment), fileClassType, file);
|
||||
ClassBuilder builder = state.getFactory().newVisitor(JvmDeclarationOriginKt.PackagePart(file, packageFragment), fileClassType, file);
|
||||
|
||||
new PackagePartCodegen(builder, file, fileClassType, packagePartContext, state).generate();
|
||||
|
||||
@@ -456,7 +429,7 @@ public class PackageCodegen {
|
||||
|
||||
public void generateClassOrObject(@NotNull JetClassOrObject classOrObject) {
|
||||
JetFile file = classOrObject.getContainingJetFile();
|
||||
Type packagePartType = FileClassesPackage.getFileClassType(state.getFileClassesProvider(), file);
|
||||
Type packagePartType = FileClasses.getFileClassType(state.getFileClassesProvider(), file);
|
||||
CodegenContext context = state.getRootContext().intoPackagePart(packageFragment, packagePartType);
|
||||
MemberCodegen.genClassOrObject(context, classOrObject, state, null);
|
||||
}
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
|
||||
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
|
||||
import org.jetbrains.kotlin.modules.TargetId;
|
||||
import org.jetbrains.kotlin.name.ClassId;
|
||||
import org.jetbrains.kotlin.name.Name;
|
||||
import org.jetbrains.kotlin.psi.*;
|
||||
import org.jetbrains.kotlin.renderer.DescriptorRenderer;
|
||||
@@ -193,7 +192,7 @@ public class InlineCodegen extends CallGenerator {
|
||||
|
||||
SMAPAndMethodNode nodeAndSMAP;
|
||||
if (functionDescriptor instanceof DeserializedSimpleFunctionDescriptor) {
|
||||
JetTypeMapper.ContainingClassesInfo containingClasses = typeMapper.getContainerClassIdForInlineCallable(
|
||||
JetTypeMapper.ContainingClassesInfo containingClasses = typeMapper.getContainingClassesForDeserializedCallable(
|
||||
(DeserializedSimpleFunctionDescriptor) functionDescriptor);
|
||||
|
||||
VirtualFile file = InlineCodegenUtil.getVirtualFileForCallable(containingClasses.getImplClassId(), state);
|
||||
|
||||
@@ -229,7 +229,7 @@ public class JetTypeMapper {
|
||||
}
|
||||
}
|
||||
|
||||
public ContainingClassesInfo getContainerClassIdForInlineCallable(DeserializedSimpleFunctionDescriptor deserializedDescriptor) {
|
||||
public ContainingClassesInfo getContainingClassesForDeserializedCallable(DeserializedCallableMemberDescriptor deserializedDescriptor) {
|
||||
DeclarationDescriptor parentDeclaration = deserializedDescriptor.getContainingDeclaration();
|
||||
ContainingClassesInfo containingClassesInfo;
|
||||
if (parentDeclaration instanceof PackageFragmentDescriptor) {
|
||||
|
||||
@@ -21,23 +21,23 @@ import org.jetbrains.kotlin.name.FqName
|
||||
public interface JvmFileClassInfo {
|
||||
public val fileClassFqName: FqName
|
||||
public val facadeClassFqName: FqName
|
||||
public val isWithJvmName: Boolean
|
||||
public val TEMP_isMultifileClass: Boolean
|
||||
public val withJvmName: Boolean
|
||||
public val withJvmMultifileClass: Boolean
|
||||
}
|
||||
|
||||
public class JvmSimpleFileClassInfo(
|
||||
override val fileClassFqName: FqName,
|
||||
override val isWithJvmName: Boolean
|
||||
override val withJvmName: Boolean
|
||||
) : JvmFileClassInfo {
|
||||
override val facadeClassFqName: FqName get() = fileClassFqName
|
||||
override val TEMP_isMultifileClass: Boolean get() = false
|
||||
override val withJvmMultifileClass: Boolean get() = false
|
||||
}
|
||||
|
||||
public class JvmMultifileClassPartInfo(
|
||||
override val fileClassFqName: FqName,
|
||||
override val facadeClassFqName: FqName
|
||||
) : JvmFileClassInfo {
|
||||
override val isWithJvmName: Boolean get() = true
|
||||
override val TEMP_isMultifileClass: Boolean get() = true
|
||||
override val withJvmName: Boolean get() = true
|
||||
override val withJvmMultifileClass: Boolean get() = true
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ public class IncrementalPackageFragmentProvider(
|
||||
if (partsData.isEmpty())
|
||||
JetScope.Empty
|
||||
else {
|
||||
val scopes = partsData.map { IncrementalPackageScope(JvmProtoBufUtil.readPackageDataFrom(it)) }
|
||||
val scopes = partsData.map { IncrementalPackageScope(JvmProtoBufUtil.readPackageDataFrom(it.data, it.strings)) }
|
||||
ChainedScope(this,
|
||||
"Member scope for incremental compilation: union of multifile class parts data for $multifileClassFqName",
|
||||
*scopes.toTypedArray<JetScope>())
|
||||
|
||||
+1
-1
@@ -220,7 +220,7 @@ public class KotlinJavaFileStubProvider<T extends WithFileStubAndExtraDiagnostic
|
||||
if (!files.isEmpty()) {
|
||||
JetFile representativeFile = files.iterator().next();
|
||||
JvmFileClassInfo fileClassInfo = NoResolveFileClassesProvider.INSTANCE$.getFileClassInfo(representativeFile);
|
||||
if (!fileClassInfo.getTEMP_isMultifileClass()) {
|
||||
if (!fileClassInfo.getWithJvmMultifileClass()) {
|
||||
PackageCodegen codegen = state.getFactory().forPackage(representativeFile.getPackageFqName(), files);
|
||||
codegen.generate(CompilationErrorHandler.THROW_EXCEPTION);
|
||||
state.getFactory().asList();
|
||||
|
||||
@@ -40,7 +40,7 @@ class RenameKotlinFileProcessor() : RenamePsiFileProcessor() {
|
||||
}
|
||||
|
||||
val fileInfo = JvmFileClassUtil.getFileClassInfoNoResolve(jetFile)
|
||||
if (!fileInfo.isWithJvmName) {
|
||||
if (!fileInfo.withJvmName) {
|
||||
val facadeFqName = fileInfo.facadeClassFqName
|
||||
val project = jetFile.project
|
||||
val facadeClass = JavaPsiFacade.getInstance(project).findClass(facadeFqName.asString(), project.allScope())
|
||||
|
||||
Reference in New Issue
Block a user