Commit Graph

323 Commits

Author SHA1 Message Date
Alexander Udalov 751ff48301 Extract logic of builtins package fragment provider creation
This allows to drop the compile dependency of module 'descriptors' on
'deserialization', breaking the circular dependency between them
2017-06-06 14:29:20 +03:00
Alexander Udalov 1728b77b2c Minor, refactor createBuiltInsPackageFragmentProvider 2017-06-06 14:29:19 +03:00
Alexander Udalov cbaa676c3d Move some declarations between 'descriptors' and 'deserialization'
- Move the following from 'deserialization' to 'descriptors':
  NotFoundClasses.kt
  AdditionalClassPartsProvider.kt
  ClassDescriptorFactory.kt
  PlatformDependentDeclarationFilter.kt
  findClassInModule.kt
- Move the following form 'descriptors' to 'deserialization':
  BuiltInSerializerProtocol.kt
  builtInsPackageFragmentProvider.kt
- Extract a marker interface from BuiltInsPackageFragment and move its
  implementation to 'deserialization'
- Change the type of parameters in PlatformDependentDeclarationFilter
  and AdditionalClassPartsProvider to ClassDescriptor

This will help in getting rid of the circular dependency of
'descriptors' <-> 'deserialization'
2017-06-06 14:29:18 +03:00
Denis Zharkov 63c5d85cf4 Optimize memory footprint for generated protobuf code
The problem was that an overload of CodedOutputStream.newInstance
without size uses 4000 as a default value, thus allocating
a 4k-sized byte array.
At the same time the array remained effectively unused
in the most cases since it only used for storing data
for unknown fields.

Because such arrays are being created for each read of
protobuf message, during compilation of IntelliJ project
it was producing 25% of redundant memory traffic.

Of course these arrays were all in the young gen, but still
they have some effect on GC
2017-05-17 14:34:11 +03:00
Pavel V. Talanov 55a0e138fc Refactor: extract AnnotationDescriptor.annotationClass utility 2017-05-02 15:40:20 +03:00
Alexander Udalov 38ea9986ab Make KotlinType.isError extension instead of member 2017-04-26 18:10:49 +03:00
Pavel V. Talanov 795a83ee24 LookupTracker.DO_NOTHING is the default implementation of LookupTracker 2017-03-30 18:59:19 +03:00
Alexander Udalov db1f039586 Serialize and deserialize 'header' modifier for descriptors
This fixes KT-17001 because now 'header' modifier is loaded correctly
for deserialized members and the standard disambiguation in
OverloadingConflictResolver.compareCallsByUsedArguments takes place,
where header members are discriminated against the corresponding impl
members

 #KT-17001 Fixed
2017-03-27 19:50:25 +03:00
Simon Ogorodnik f56af41d1e Fix TypeAliasConstructorDescriptor's to create only once when required
Some IDE features relates onto that same descriptors will remain same
between resolve calls
Fix it to be true for TypeAliasConstructorDescriptor's

 #KT-16265 fixed
2017-03-20 16:55:40 +03:00
Mikhail Glukhikh b121bf8802 Cleanup: fix some compiler warnings (mostly deprecations, javaClass) 2017-03-15 17:35:31 +03:00
Mikhail Glukhikh d0cc1635db Cleanup: apply "Use synthetic property access syntax" 2017-03-15 16:13:40 +03:00
Alexander Udalov 25c1828288 JS: write and load pre-release flag on binaries 2017-03-03 13:33:51 +03:00
Alexander Udalov de8dd37e44 Change DeserializedContainerSource.presentableFqName to String
To allow outputting something other than "Class 'XXX'" in the diagnostic
message for declarations deserialized from JS
2017-03-03 13:33:51 +03:00
Alexander Udalov b52b90c182 Extract serialization of packageFqName extension to SerializerExtensionBase 2017-03-03 13:33:51 +03:00
Alexander Udalov 5a00a97cf1 Extract common parts from deserialization of built-ins and JS 2017-03-03 13:33:50 +03:00
Alexander Udalov 3cb8f1ab20 Drop BuiltIns protobuf message, use ProtoBuf.PackageFragment instead 2017-03-03 13:33:50 +03:00
Alexander Udalov a36e457c12 Introduce PackageFragment protobuf message for kjsm/builtins/common metadata 2017-03-03 13:33:50 +03:00
Alexander Udalov e19c1b5364 Drop MockTypeAliasDescriptor, use MockClassDescriptor instead
It's irrelevant whether the non-found classifier is a class or a
typealias
2017-02-28 20:19:58 +03:00
Alexander Udalov 794cc1e3be Refactor API of NotFoundClasses
Move deserialization-related stuff to TypeDeserializer, because it's
going to be used in other places besides deserialization
2017-02-28 20:19:58 +03:00
Alexander Udalov 86994f81c3 Refactor ClassId.getOuterClassId, make it nullable 2017-02-28 20:19:57 +03:00
Stanislav Erokhin 0a24bf1613 Fix type deserialization for suspend function types which was written by pre-release compiler.
Notes: if arity == 0, it means that type was `suspend () -> String` => arguments.size == 1, and it means that SuspendFunction0 has only one type argument and it is return type.
2017-02-21 17:26:07 +03:00
Alexander Udalov bae955aafd Serialize metadata for Cloneable and discard it during deserialization
#KT-16358 Fixed
2017-02-15 20:43:25 +03:00
Alexander Udalov a1a71a01b1 Drop JvmMetadataVersion.skipCheck, support this correctly
Pass the value of this flag via DeserializationConfiguration
2017-02-15 10:46:48 +03:00
Stanislav Erokhin a4272caa8c Fix serialization for suspend function types.
Since now `suspend (Int) -> String` will be serialized as `(Int, Continuation<String>) -> Any?` + suspend flag.

Before this change such type serialized like this: Function2<Int, String> + suspend flag. And yes, type `Function2<Int, String>` isn't correct, because Function2 expect 3 type arguments.
We have special logic for this case and we deserialize such error-written types correctly.

(cherry picked from commit 3518cbe)
2017-02-02 16:48:59 +03:00
Alexander Udalov 63c24c56ec JS: serialize .kjsm package-wise, adapt decompiler & stub builder
Instead of multiple .kjsm files for different classes and .kotlin_string_table,
.kotlin_file_table, .kotlin_classes files for each package, serialize the
contents of each package to a single foo/bar/baz/baz.kjsm file. The short name
of the file is the last segment in the FQ name of the package, or
"root-package" if the package is root.

There are two main reasons for this change:
1) Such structure takes less space, is more IO-friendly and will not cause
   multiple exceptions as the old one, where we sometimes tried to read
   non-existing files
2) This is exactly the same format that is used to serialize built-in
   declarations (.kotlin_builtins) at the moment, which will allow us to reuse
   some code

Also write a separate Header protobuf message to the beginning of the .kjsm
file. This will be used as arguments of the kotlin.Metadata annotation are used
in the JVM-specific parts of the compiler: to be able to provide some general
information about the binary file without parsing the whole protobuf data.

This commit breaks decompiled text & stub builder consistency tests. This is OK
because they're removed in a future commit.

Fixes EA-79605, EA-81947, EA-84277 and maybe EA-86787

 #KT-10894 Fixed
 #KT-14124 Fixed
 #KT-15755 Fixed
2017-01-30 11:31:02 +03:00
Alexander Udalov f1cd2ee6fd Introduce PropertyDescriptor.isDelegated, write new flag to metadata
#KT-8384 In Progress
2017-01-23 12:25:34 +03:00
Alexander Udalov 7107ee2eeb Write/load subclasses of sealed classes in metadata
Note that now DeserializedClassDescriptor.getSealedSubclasses works a lot
faster than before, for all newly compiled sealed classes except empty ones. It
may be optimized further if we look at the metadata version of the file the
class was loaded from, however it's not easy currently because
DeserializedClassDescriptor is declared in common (non-JVM) code and has no
direct access to the binary version information.

This will also allow to add a reflection API to get subclasses of a sealed
class

 #KT-12795 Fixed
2017-01-10 12:23:26 +03:00
Alexander Udalov 75a4958144 Introduce ClassDescriptor.getSealedSubclasses
#KT-12795 In Progress
2017-01-10 12:23:25 +03:00
Dmitry Jemerov bc22b67995 Index and locate .kotlin_metadata files in IDE 2016-12-19 17:40:13 +01:00
Dmitry Petrov 80bd916f5d 'SuspendFunction$n' should not be visible in member scopes (should be unresolved).
'SuspendFunction$n' class descriptors are created on demand by KotlinBuiltIns (and cached).
On serialization, types constructed with 'SuspendFunction$n' are written as 'Function$n' with extra flag (SUSPEND_TYPE).
On deserialization, corresponding 'SuspendFunction$n' classes are used.
2016-12-15 23:58:05 +03:00
Stanislav Erokhin 42440f50dc Remove soft keyword coroutine & isCoroutine from ValueParameterDescriptor. 2016-12-15 23:57:56 +03:00
Alexander Udalov e50b102e89 Treat absence of version in SinceKotlinInfo as infinite version
This may be needed in the future to make some declarations erroneous for all
versions of compilers
2016-12-15 11:46:18 +03:00
Alexander Udalov ede60efda5 Support SinceKotlinInfo for deserialized classes 2016-12-15 11:46:18 +03:00
Alexander Udalov 5c1adb1258 Serialize SinceKotlinInfo and SinceKotlinInfoTable 2016-12-15 11:46:17 +03:00
Alexander Udalov feeed98323 Introduce SinceKotlinInfo, load from serialized metadata
This is a way for future compilers to cause previous compilers to report
diagnostics on usages of some declarations. Diagnostic can have a message
(and/or error code), level (error, warning, or completely hide the declaration
from the resolution), and Kotlin version, since which the diagnostic should no
longer be reported
2016-12-15 11:46:17 +03:00
Stanislav Erokhin 59efedf610 Rename platform to header. 2016-12-13 18:00:00 +03:00
Alexander Udalov 789483e1eb Remove old mechanism of metadata version error reporting 2016-12-09 01:59:36 +03:00
Alexander Udalov b943ed26f3 Report incompatible metadata version error correctly
Similarly to pre-release classes, load metadata for the class anyway and allow
the resolution to select it as the result and prohibit its usage in the end
with the special diagnostic reported in MissingDependencyClassChecker
2016-12-09 01:59:36 +03:00
Alexander Udalov 7de0cfde16 Report error on pre-release top level members 2016-12-09 01:59:34 +03:00
Alexander Udalov 4e99349f1f Write "pre-release" flag to class files, do not allow usages in release 2016-12-09 01:59:33 +03:00
Alexey Andreev 7a6b510ddb Include external modifier to serialized descriptors for classes and properties 2016-12-08 15:41:40 +03:00
Alexey Andreev ba2443bcb3 Add external property to class and property descriptors 2016-12-08 15:41:38 +03:00
Alexander Udalov 41f2048f96 Minor, introduce DeserializedContainerSource 2016-12-07 21:46:37 +03:00
Alexander Udalov 3b18531b20 Add expectedVersion to IncompatibleVersionErrorData, move to deserialization 2016-12-07 21:46:36 +03:00
Alexander Udalov ce9691cd2b Support platform/impl modifiers for properties
Do not allow platform properties to have backing fields, initializers, be
delegated, lateinit or const, or have accessors with bodies
2016-11-25 20:50:18 +03:00
Alexander Udalov 6e2ef9b1d2 Add platform/impl soft keywords, add isPlatform/isImpl to MemberDescriptor 2016-11-25 20:50:17 +03:00
Alexander Udalov 0dc31af73d Introduce KotlinMetadataFinder#hasMetadataPackage
Before creating a MetadataPackageFragment, check that the corresponding
directory (across the classpath) contains at least one .kotlin_metadata file.
Otherwise we're creating packages for every simple name queried during the
resolution and sometimes prefer a (empty) package to the existing class, for
example when the latter class is star-imported
2016-11-25 20:50:15 +03:00
Alexander Udalov bfb7b21472 Load definitions of symbols from .kotlin_metadata files
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
2016-11-25 20:50:13 +03:00
Alexander Udalov c0b5fd193a Refactor DeserializedPackageFragment and subclasses
Push loadResource and loadResourceSure down to KotlinJavascriptPackageFragment,
as it's no longer needed in BuiltInsPackageFragment
2016-11-22 18:19:02 +03:00
Alexander Udalov 19520bf29c Extract KotlinMetadataFinder interface out of KotlinClassFinder 2016-11-22 18:19:02 +03:00