Instead of requiring to pass it in SerializerExtensionBase's
constructor, pass it always in serializePackage. This is more
straightforward and helps in a situation where one SerializerExtension
instance is used for the whole module, not one per-package
Extract AbstractDeserializedPackageFragmentProvider out of
JvmBuiltInsPackageFragmentProvider and implement it a little bit differently in
MetadataPackageFragmentProvider. The main difference is in how the package
fragment scope is constructed: for built-ins, it's just a single scope that
loads everything from one protobuf message. For metadata, package scope can
consist of many files, some of which store information about classes and others
are similar to package parts on JVM, so a ChainedMemberScope instance is
created.
Introduce a bunch of interfaces/methods to deliver the needed behavior to the
'deserialization' module which is not JVM-specific and does not depend on the
compiler code: MetadataFinderFactory,
PackagePartProvider#findMetadataPackageParts, KotlinMetadataFinder#findMetadata.
Note that these declarations are currently only implemented in the compiler; no
metadata package parts/fragments will be found in IDE or reflection
Compilation of top level functions/properties/typealiases results in a bunch of
different .kotlin_metadata files, so we need to store names of these files to
avoid scanning the file system in the compiler when loading code compiled by
K2MetadataCompiler.
For this, we reuse the PackageTable protobuf message, which is already used for
exactly the same purpose in the JVM back-end
Do not serialize everything in the same package to the same file (as is done
for built-ins) because this approach is unfriendly to incremental compilation,
which is going to be supported in the future. Instead, similarly to JVM
serialize each class to its own file, and each source file with top-level
callables/typealiases to its own file.
E.g. if a file named test.kt contains a class Foo and some
functions/properties, the output will contain two files: TestKt.kotlin_metadata
and Foo.kotlin_metadata. Each one of this files contains the serialized
BuiltIns message (see builtins.proto)
K2MetadataCompiler is a compiler facade similar to K2JVMCompiler and
K2JSCompiler and it produces .kotlin_metadata files. Each .kotlin_metadata file
contains the binary data which is a serialized BuiltIns protobuf message.
There's no 'kotlinc-***' script yet though, so to run this compiler currently
invoke this:
KOTLIN_COMPILER=org.jetbrains.kotlin.cli.metadata.K2MetadataCompiler kotlinc
It's going to be needed to be able to report configuration errors when running
built-ins serializer (e.g. no output destination is passed as an argument)
- Document what exactly should findPackageParts return
- Make EMPTY a named object instead of a val in the companion
- Do not use JvmPackagePartProvider in tests where Empty works fine
- Add a couple default values to arguments of setupResolverForProject
Without such shutdown console program that gets PSI file will hang forever.
Introduced in https://github.com/JetBrains/intellij-community/commit/446b80077aed71e2384301ae993cf44416bf9a83
Stack example:
java.lang.Thread.State: RUNNABLE
at com.intellij.util.concurrency.AppDelayQueue.<init>(AppDelayQueue.java:37)
at com.intellij.util.concurrency.AppScheduledExecutorService.<init>(AppScheduledExecutorService.java:50)
at com.intellij.util.concurrency.AppScheduledExecutorService$Holder.<clinit>(AppScheduledExecutorService.java:41)
at com.intellij.util.concurrency.AppScheduledExecutorService.getInstance(AppScheduledExecutorService.java:46)
at com.intellij.util.concurrency.AppExecutorUtil.getAppScheduledExecutorService(AppExecutorUtil.java:39)
at com.intellij.concurrency.JobScheduler.getScheduler(JobScheduler.java:43)
at com.intellij.psi.impl.source.AstPathPsiMap.<clinit>(AstPathPsiMap.java:45)
at com.intellij.psi.impl.source.PsiFileImpl.<init>(PsiFileImpl.java:76)
at com.intellij.extapi.psi.PsiFileBase.<init>(PsiFileBase.java:39)
at org.jetbrains.kotlin.psi.KtFile.<init>(KtFile.java:48)
at org.jetbrains.kotlin.parsing.KotlinParserDefinition.createFile(KotlinParserDefinition.kt:73)
at com.intellij.psi.SingleRootFileViewProvider.createFile(SingleRootFileViewProvider.java:407)
at com.intellij.psi.SingleRootFileViewProvider.createFile(SingleRootFileViewProvider.java:348)
at com.intellij.psi.SingleRootFileViewProvider.createFile(SingleRootFileViewProvider.java:326)
at com.intellij.psi.SingleRootFileViewProvider.getPsiInner(SingleRootFileViewProvider.java:171)
at com.intellij.psi.SingleRootFileViewProvider.getPsi(SingleRootFileViewProvider.java:155)
at com.intellij.psi.impl.PsiFileFactoryImpl.trySetupPsiForFile(PsiFileFactoryImpl.java:121)
at com.intellij.psi.impl.PsiFileFactoryImpl.createFileFromText(PsiFileFactoryImpl.java:100)
at com.intellij.psi.impl.PsiFileFactoryImpl.createFileFromText(PsiFileFactoryImpl.java:56)
at org.jetbrains.kotlin.psi.KtPsiFactory.doCreateFile(KtPsiFactory.kt:174)
at org.jetbrains.kotlin.psi.KtPsiFactory.createFile(KtPsiFactory.kt:178)
at org.jetbrains.kotlin.preprocessor.Preprocessor.processFileSingleEvaluator(Preprocessor.kt:82)
at org.jetbrains.kotlin.preprocessor.Preprocessor.processDirectorySingleEvaluator(Preprocessor.kt:105)
at org.jetbrains.kotlin.preprocessor.Preprocessor.processDirectorySingleEvaluator(Preprocessor.kt:135)
at org.jetbrains.kotlin.preprocessor.Preprocessor.processSources(Preprocessor.kt:74)
at org.jetbrains.kotlin.preprocessor.PreprocessorCLI.main(PreprocessorCLI.kt:35)
- move enums and messages nested in Callable to top level, since they're likely
to be reused in other messages soon
- delete obsolete comments: some did not any value, some became obsolete with
custom options ("id in StringTable" -> name_id_in_table)
Rework SerializerExtension interface: don't pass StringTable to each method
every time, create it in each extension's constructor instead and expose to
DescriptorSerializer with an interface method