Commit Graph

1261 Commits

Author SHA1 Message Date
Alexander Udalov 6e2ef9b1d2 Add platform/impl soft keywords, add isPlatform/isImpl to MemberDescriptor 2016-11-25 20:50:17 +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 32792c5ce4 Store .kotlin_module files in MetadataSerializer
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
2016-11-25 20:50:12 +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
Dmitry Petrov fc2a965d2a Fix decompiler tests. 2016-11-22 14:40:02 +03:00
Alexander Udalov 61767bb0ea Minor, annotate visibility constants with NotNull
To avoid nullability warnings on ClassDescriptor#getVisibility and
implementations
2016-11-11 19:00:08 +03:00
Alexander Udalov 8c65379711 Support injecting custom module into KotlinBuiltIns
Provide a command-line option to load built-ins from the module and its
dependencies instead of looking for them in kotlin-compiler.jar; built-ins must
be found this way, or an error will be reported (or, most likely at this
moment, an exception will be thrown).

Note that this does not affect whether built-ins (loaded from one place or the
other) are added to the _dependencies_ of the module, this is controlled by
another option. The option added in this commit only makes the KotlinBuiltIns
instance which is used via ModuleDescriptor throughout the compiler front-end
(and also injected in a bunch of places) a sort of "helper" which always goes
to that same module to find descriptors for built-in classes
2016-11-08 12:14:24 +03:00
Alexander Udalov 5cd9e11f44 Refactor initialization of JvmBuiltIns instance
Use lazy val instead of lateinit var + implicit dependency on the code in
KotlinBuiltIns constructor
2016-11-08 12:14:23 +03:00
Alexander Udalov e0989caf46 Load built-ins from module dependencies in JVM compiler
Introduce a new method KotlinClassFinder#findBuiltInsData, which is only
implemented correctly in the JvmCliVirtualFileFinder because it's only used in
the compiler code at the moment.

Introduce JvmBuiltInsPackageFragmentProvider, the purpose of which is to look
for .kotlin_builtins files in the classpath and provide definitions of
built-ins from those files.

Also exclude script.runtime from compilation because, as other excluded
modules, it has no dependency on the stdlib and is no longer compilable from
the IDE now, because it cannot resolve built-ins from anywhere
2016-10-26 16:31:09 +03:00
Alexander Udalov 484b0e36fb Add KotlinBuiltIns#isBuiltIn, use it instead of other utilities 2016-10-26 16:31:05 +03:00
Alexander Udalov 2b34d62848 Extract superclass from FunctionClassScope and CloneableClassScope 2016-10-26 16:31:03 +03:00
Alexander Udalov 4e7542b07d Filter out non-builtin package fragments from module when needed
In subsequent commits, a JVM module will be able to have up to two package
fragments for a given package FQ name. For example, for package "kotlin" in
kotlin-runtime.jar there will be a LazyJavaPackageFragment with binary
(Kotlin+Java) dependencies, and a BuiltInsPackageFragment for built-ins
metadata (which is loaded from kotlin/kotlin.kotlin_builtins)
2016-10-25 15:42:33 +03:00
Alexander Udalov 035d6156a7 Drop Cloneable in JS, synthesize it at compile-time on JVM
Use the same approach that is used for creating function type classes
(Function{0,1,...}) + add Cloneable to supertypes of Array and primitive arrays

 #KT-5537 Fixed
2016-10-25 15:42:33 +03:00
Alexander Udalov 0f4b10d37d Add JavaToKotlinClassMap#isJavaPlatformClass
Use it instead of mapPlatformClass where we only need to check emptiness
because mapPlatformClass requires built-ins and it's not always easy to come up
with the correct instance of built-ins.

In KotlinEvaluationBuilder, use the nullable function
findClassAcrossModuleDependencies instead of mapPlatformClass which uses the
throwing resolveClassByFqName. This is necessary because DefaultBuiltIns, which
are used there, are not always able to find classes mapped by a _Java_ to
Kotlin class map. (The correct solution would be not to use DefaultBuiltIns at
all, instead obtaining the correct instance of built-ins, which are almost
certainly going to be JvmBuiltIns, from the project configuration.)
2016-10-25 15:42:32 +03:00
Alexander Udalov 2f81d48f5e Use ClassId instead of FqName in JavaToKotlinClassMap
Extract mapJavaToKotlin which returns ClassId and needs no KotlinBuiltIns
instance
2016-10-25 15:42:32 +03:00
Alexander Udalov c0147860bd Allow multiple ClassDescriptorFactory instances in deserialization 2016-10-25 15:42:32 +03:00
Alexander Udalov cdf6567375 Drop TypeConstructor.getAnnotations(), uninherit TypeConstructor from Annotated
The method was unused on TypeConstructor instances, and almost all
implementations returned EMPTY anyway
2016-10-24 15:30:38 +03:00
Dmitry Petrov 3d0288ffed Annotations on type aliases: generate synthetic method for type alias annotations. 2016-10-13 17:52:21 +03:00
Alexander Udalov 88af36001c Introduce DeserializationConfiguration
Will be used soon to deliver the language/API-version-related behavior to the
deserialization
2016-10-12 12:19:17 +03:00
Michael Bogdanov dfd5be1a33 Generate all bodies in interfaces as default methods 2016-10-03 13:50:11 +03:00
Alexander Udalov 97f2051a03 Add debugName to ModuleMapping 2016-10-02 21:03:33 +03:00
Alexander Udalov 278941a8a1 Deduplicate code in container creation for JVM analysis 2016-10-02 21:03:24 +03:00
Denis Zharkov 5381c06936 Improve 1.0-compatibility mode for JDK dependent members
Just reporting error by call checker may be too restrictive
in case there are some extensions that can be used successfully

Solution is to annotate additional members with
@Deprecated(level=Error) + @kotlin.internal.LowPriorityInOverloadResolution
2016-09-22 15:40:37 +03:00
Denis Zharkov a7dedfab70 Move JvmBuiltIns initialization after container setup
It will be used in the further commits to initilize built-ins instance
with components as arguments
2016-09-22 15:40:37 +03:00
Dmitry Petrov 07198cf86d SAM constructors for type aliases. 2016-09-22 10:38:34 +03:00
Dmitry Petrov 796d11c860 ClassDescriptor is now a super-interface for ClassConstructorDescriptor and TypeAliasConstructorDescriptor. 2016-09-20 10:55:36 +03:00
Alexander Udalov 81556b1339 Fix AssertionError in notFoundClasses.kt on bad FQ names (EA-85046)
FQ names like "Foo." or "Foo..Bar" were causing this exception. No tests added:
no idea how to reproduce this exception
2016-09-12 10:39:21 +03:00
Denis Zharkov fc5217f7fc Fix signature clash problems caused by special built-ins
Do not treat members with already changed signature as a reason
to create a hidden copy

See tests for clarification:
- There are `charAt` method in B that has different name in Kotlin - `get`,
  i.e. relevant descriptor has initialSignatureDescriptor != null
- When collecting methods from supertypes, `charAt` from A is also get
  transformed to `get`
- So it has effectively the same signature as B.get (already declared)
- If by an accident B.get had been declared with Kotlin signature
  we would have add A.charAt (after transformation) with special flag:
  HiddenToOvercomeSignatureClash (hides it from resolution)
- But here B.charAt was artificially changed to `get`, so no signature clash
  actually happened

 #KT-13730 Fixed
2016-09-09 16:33:32 +03:00
Denis Zharkov aee2509bf2 Minor. Replace lambdas with callable references in LazyJavaClassMemberScope 2016-09-09 16:33:32 +03:00
Denis Zharkov a29faf3f2d Minor. Rename MemberIndex -> DeclaredMemberIndex
Also replace super-calls with explicit calls to declaredMemberIndex().getMethods
2016-09-09 10:27:35 +03:00
Denis Zharkov 44f5df00fe Do not return nested/local classes as a part of package fragment
#KT-13757 Fixed
2016-09-09 10:27:35 +03:00
Denis Zharkov 4bf61db9f9 Optimize class names computation in Java package for CLI
Use known class names' set if it exists
2016-09-09 10:27:35 +03:00
Denis Zharkov 5a2851308f Optimize computation of member names in Java scopes
Effectively all custom logic was moved from MemberIndex to JavaScope classes,
and as member names are being cached there, so it prevents repeating supertypes
traversal (see getAllMemberNames extension)
2016-09-09 10:27:35 +03:00
Denis Zharkov cc0f2e87d4 Optimize java scope members computation for non-existing names
Do not use memoized function if member with given name is not contained in the scope

There are a lot of queries with names of non-existent functions, that leads to many
effectively redundant Map nodes in MemoizedFunction and also cause
additional computation that is worth to compute at once
2016-09-09 10:27:35 +03:00
Denis Zharkov e428ea8dd5 Minor. Refine return type Collection -> Set 2016-09-09 10:27:35 +03:00
Denis Zharkov 02d7cf9614 Minor. Rename get*Names -> compute*Names
To indicate that repeating calls to them may require additional computations

Also change second parameter to be nullable, this will be necessary in the next commits
2016-09-09 10:27:35 +03:00
Denis Zharkov 81682f0497 Optimize JvmBuiltinsSettings.getFunctionsNames 2016-09-09 10:27:35 +03:00
Denis Zharkov b1edb01dd4 Introduce getFunctionNames and getVariableNames into MemberScope
Also provide some basic implementation

The main purpose of these methods is optimization.
Most of the member scopes store mapping from names to descriptors
MemoizedFunction<Name, Collection<Descriptor>>

While there are 10 functions in class in average, there are a lot of
queries with names of non-existent functions, that leads to many
effectively redundant Map nodes in MemoizedFunction and also cause
additional computation that is worth to compute at once
2016-09-09 10:27:35 +03:00
Denis Zharkov 86c1dbe7b5 Fix decompilation of types based on local classifiers
If deserializing a type with arguments based on a local class for
decompiler, then just return Any type (without arguments).

Previously Any constructor was used with serialized arguments, that lead
to exception

Note that in case of deserialization for compiler nothing changes about
local-classes-based types (LocalClassifierResolverImpl is just inlined)

 #KT-13408 Fixed
2016-09-05 17:54:36 +03:00
Michael Bogdanov 7325baa06a Fix for KT-13374: CompilationException: Inline function call with anonymous object implementing an interface by delegation
#KT-13374 Fixed
2016-08-16 10:47:01 +03:00
Alexander Udalov 18887f8bec Rename CompanionObjectMapping.hasMappingToObject -> isMappedIntrinsicCompanionObject 2016-08-15 19:41:47 +03:00
Alexander Udalov 611899e9d3 Minor, make CompanionObjectMapping a singleton 2016-08-15 19:41:47 +03:00
Pavel V. Talanov 252b8ec6db Add assertions to prohibit creating LazyJavaClassDescriptor by KtLightClass
Diagnosing KT-12966
2016-08-03 17:29:08 +03:00
Pavel V. Talanov 30892e0154 KtLightClassForDecompiledDeclaration is now marked by KtLightClassMarker
Rename: KtJavaMirrorMarker -> KtLightClassMarker
Introduce code to be able to tell light classes from source and binaries apart in 'frontend.java'
2016-08-03 17:29:06 +03:00
Denis Zharkov 915e36cb02 Add Map.getOrDefault method as PlatformDependent declaration with refined signature
- First parameter should have type of K instead of Any
- Special bridge should return second parameter if a key has wrong type
- Special bridge may throw an exception if defaultValue has wrong type

 #KT-13209 Fixed
2016-07-27 18:46:13 +03:00
Denis Zharkov 169acf2f31 Refine method's contract and rename it
Basically what's it checked before is that
receiver is a valid override of raw version of builtinWithErasedParameters

While we need to check that method has the same JVM descriptor as builtinWithErasedParameters,
but it's not a valid override of latter

It's important for 'getOrDefault(Object k, V value)' ('getOrDefault(K k, V value)' in Kotlin):
'getOrDefault(Object k, V value)' is not override of 'getOrDefault(Object k, Object value)',
that leads to incorrect loading of former method (like it's not an override of declaration in Map)
2016-07-27 18:46:13 +03:00
Denis Zharkov 15b94bb8df Minor. Move method closer to it's usage and simplify it 2016-07-27 18:46:13 +03:00
Alexander Udalov 720c29e8f4 Minor, fix NonExistentClass name and format 2016-07-07 13:56:01 +03:00
Denis Zharkov 7723a3a105 Refine definition of whether single parameter the method should be boxed
Only 'Collection<Int>.remove(E): Boolean' should match
2016-07-04 15:44:00 +03:00