Commit Graph

1353 Commits

Author SHA1 Message Date
Alexander Udalov 1273ac9647 Remove dependency of module 'descriptors' on 'deserialization' 2017-06-06 14:29:21 +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
Alexander Udalov bfb3b38ebc Do not try to load Java classes from incorrect packages
#KT-11474 Fixed
2017-05-18 13:30:06 +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 798c80ed07 Use wrappers around java.util.* to emulate kotlin.collection.* behaviour
Backend: If kotlin class extends kotlin.collection.List
    write it as it's super interface (light class mode only)
IDE: Provide wrapper classes to java resolve
    that try to emulate backend behaviour

For example if kotlin class implements kotlin.collections.Map,
    we provide a superinterface that has abstract 'getEntries' method
    and 'entrySet' method that is considered default.
In reality all those methods are generated in the class itself.

In IDE supporting this case without hacks is not feasible performance-wise
    since kotlin.collection.* may not be an immediate supertype and we need
    to compute all supertypes just to calculate own methods of the class
2017-05-16 22:01:03 +03:00
Pavel V. Talanov 1a04960ff0 J2K class map: expose classes having mutable/readonly kotlin equivalents
Refactor JavaToKotlinClassMap a little bit
2017-05-16 22:00:59 +03:00
Pavel V. Talanov 40561dabed J2K JavaToKotlinClassMap 2017-05-16 22:00:58 +03:00
Mikhail Zarechenskiy 7541a3754d Move SAM constructors to synthetic scope 2017-05-05 21:30:35 +03:00
Mikhail Zarechenskiy 95ede7fb67 Move SAM adapters from static scope to synthetic one 2017-05-05 21:30:10 +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
Alexey Tsvetkov 50085722d1 Fix internal visibility check for deserialized typealiases
#KT-15495 fixed
2017-04-25 16:27:23 +03:00
Denis Zharkov 62a55b7b00 Fix false-positive resolution ambiguity when using akka
com.typesafe.akka:akka-cluster-sharding_2.12:2.5
akka.cluster.sharding.ClusterSharding  has the following methods:

    public static ClusterSharding get(ActorSystem var0) {
        return ClusterSharding$.MODULE$.get(var0);
    }

    public static Extension get(ActorSystem var0) {
        return ClusterSharding$.MODULE$.get(var0);
    }

NB: ClusterSharding  <: Extension
None of these methods is synthetic or something, but javac allows
calls like ClusterSharding.get(null)  and they get resolved
to the first method returning ClusterSharding

It seems that both javac and IntelliJ resolution algorithms filter out
such clashing declarations choosing the one that has the most
specific return type, the same idea is applied in the change

 #KT-17560 Fixed
2017-04-24 17:54:01 +03:00
Denis Zharkov 513655239d Introduce initializer-related properties into JavaField
It's much more convenient to use and implement these
properties instead of manual "pattern matching" in the
JavaPropertyInitializerEvaluatorImpl
2017-04-21 12:56:30 +03:00
Denis Zharkov 506d7ab3d2 Replace JavaClass.innerClasses with innerClassNames
Also add a findInnerClass method that can find an inner class
by its name

This change helps to avoid loading all the inner class files
eagerly (that may be rather slow), while all the names are available
in InnerClass attribute
2017-04-21 12:48:31 +03:00
Denis Zharkov 5936424659 Replace JavaClassifierType.canonicalText with classifierQualifiedName
The reason is that canonicalText requires some additional
computations to be done when reading class files, while
in fact we only need a class name of the type
2017-04-21 12:48:31 +03:00
Denis Zharkov 06ffbb7b93 Minor. Avoid repeating calls to isRaw 2017-04-21 12:48:31 +03:00
Denis Zharkov e4cb5496b8 Optimize getSingleAbstractMethodOrNull
Searching for the single abstract method leads to computing
whole member scopes of given intrefaces, especially when
they contain a lot of methods (i.e. they're definitely not SAMs)

On the other side this method is very hot because it's called
for each Java interface used as a type for some value parameter
(for building SAM adapters)

The idea is to apply some heuristics to understand using only
JavaMethod and supertypes that this interface is definitely not a SAM
2017-04-21 12:48:31 +03:00
Christopher Horner 8df40eaa46 Add support for RxJava's nullability annotations. 2017-04-20 17:20:39 +03:00
Dmitry Jemerov 03a26c4ce0 Set language level 6 for modules using JDK 6 2017-03-29 18:41:00 +02: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
Alexander Udalov af5fbef4ea Use JDK 1.6 to compile modules under "core"
Outputs of these modules go into kotlin-stdlib and kotlin-reflect, both
of which must be usable on Java 6
2017-03-21 13:03:18 +03:00
Pavel V. Talanov 6924ddeace Clarify logic in KotlinTypeMapper.mapType() dealing with enum entries
This allows to write correct class signatures for enum entries
    regardless of whether ASM_TYPE slice was written to
2017-03-15 20:51:20 +03:00
Mikhail Glukhikh 045a23ae10 Cleanup: apply "Convert lambda to reference" 2017-03-15 17:36:02 +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
Mikhail Glukhikh 1375267996 Cleanup: apply redundant curly braces in string template inspection 2017-03-15 16:13:22 +03:00
Dmitry Jemerov 8d1d76cdae Try to recover from corrupt VFS data for a .kotlin_module file
#KT-13135 Fixed
2017-03-14 13:06:29 +01:00
Denis Zharkov 7173e56393 Make computation of arguments for raw types lazy
See how we translate raw types to Kotlin model:
RawType(A) = A<ErasedUpperBound(T1), ...>
ErasedUpperBound(T : G<t>) = G<*> // UpperBound(T) is a type G<t> with arguments
ErasedUpperBound(T : A) = A // UpperBound(T) is a type A without arguments
ErasedUpperBound(T : F) = UpperBound(F) // UB(T) is another type parameter F

Stack overflow happens with the following classes:
class A<X extends B> // NB: raw type B in upper bound
class B<Y extends A> // NB: raw type A in upper bound

when calculating raw type for A, we start calculate ErasedUpperBound(Y),
thus starting calculating raw type for B => ErasedUpperBound(X) => RawType(A),
so we have SOE here.
The problem is that we calculating the arguments for these raw types eagerly,
while from the definition of ErasedUpperBound(Y) we only need a type constructor
of raw type B (and the number of parameters), we don't use its arguments.

The solution is to make arguments calculating for raw types lazy

 #KT-16528 Fixed
2017-03-10 13:30:33 +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 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 de2117663c Fix overload resolution ambiguity on *Array.clone() with runtime 1.0
#KT-16371 Fixed
2017-02-16 18:46:05 +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
Alexander Udalov 4c9afb9d20 Move testable IS_PRE_RELEASE flag to KotlinCompilerVersion
It'll be used in the JS back-end as well soon, so
DeserializedDescriptorResolver is not the best place for it
2017-02-13 12:11:15 +03:00
Alexander Udalov 6d16ea0a3a Fix reflection on top level declarations from other modules
The main problem here is that moduleName that is being passed to KPackageImpl
is useless: as can be seen in
ClosureCodegen.generateCallableReferenceDeclarationContainer, the name of the
current module is always written to the class file for a callable reference,
not the name of the module of the referenced declaration. This resulted in
reflection not loading the correct .kotlin_module file and subsequently not
finding the required file facade for a top-level function.

The commit does not fix the issue with the incorrect module name written in the
back-end, but workarounds it. It turns out, reflection can figure out the name
of the module of the referenced declaration itself by parsing the header from
the given java.lang.Class object for a single-file/multi-file package facade
and extract the package_module_name protobuf extension. Similar code was
already there in Member.getKPackage() in ReflectJvmMapping.kt but it did not
support multi-file classes, of which there are a lot in the standard library;
this is now supported

 #KT-12630 Fixed
 #KT-14731 Fixed
2017-02-08 19:23:18 +03:00
Denis Zharkov 1bb40afada Simplify compatibility mode with ll=1.0 on JDK dependent built-ins
A lot of problem arise with current solution
(loading them with lowpriority annotation + additional call checkers):
- We errorneously treated ArrayList.stream as an existing method, while
  it's just a fake override from List
- The same problem arises when creating a class delegating to List.
  Also the latter case is failing with codegen internal error
  (see issue KT-16171)

The negative side of this solution is that instead of reporting meaningful
diagnostic, there will be UNRESOLVED_REFERENCE.
But it seems to be better than having strange problems like ones described above.

 #KT-16073 Fixed
 #KT-16171 Fixed
2017-02-08 16:04:19 +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
Dmitry Jemerov bc9c40883c Avoid repeated reading of file contents from disk while building stubs 2017-02-01 18:14:57 +01:00
Simon Ogorodnik c2ba4e3ab9 KT-14252 Completion could suggest constructors available via typealiases
#KT-14252 fixed
2017-01-31 15:14:18 +03:00
Alexander Udalov 268d10d3f0 Advance JvmMetadataVersion to 1.1.4, change IS_PRE_RELEASE to false
Kotlin 1.1 is no longer considered a pre-release
2017-01-30 16:00:05 +03:00
Stanislav Erokhin e38ca44595 Create different KotlinBuiltIns for modules with different language feature settings.
For sdkModule we create builtIns with default language feature settings.
Also when we create sdkModuleResolverProvider we create builtIns cache.
Then for every other module we get builtIns cached by value isAdditionalBuiltInsFeatureSupported.
2017-01-28 19:13:48 +01:00
Denis Zharkov 0e132b9857 Move all coroutine-related declarations from built-ins to stdlib
Also move internal declarations from runtime.jvm module into new package
kotlin.coroutines.jvm.internal in stdlib

The necessity of these declarations being in built-ins is controversial,
but also it will complicate the migration of current coroutine runtime
to a separate jar if we ever need this
2017-01-27 23:24:13 +03:00
Alexey Tsvetkov b9dbe69232 Rebuild all kotlin files when EAP flag is changed 2017-01-26 13:38:52 +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
Denis Zharkov 4ab6b6954d Fix false positive "Null can not be a value of a non-null type"
Inferred type of receiver of orElse  is Optional<T & Any>
Generic descriptor is orElse(E!): E!
Substituted descriptor is orElse(T): T , and that is the problem.

Seems that E!  => (T & Any)!  gets expanded to just T  or T & Any , however it should be expanded to
(T & Any) .. (T & Any)?  => T & Any .. T & Any

T & Any is NotNullTypeParameter(T)

The problem is that (T & Any)?  is expanded to T & Any,
that is seems to be wrong.

 #KT-15236 Fixed
2017-01-19 10:20:35 +03:00
Denis Zharkov 5d4f51d9b6 Refine 1.0-compatibility mode for JDK dependent members
- calls must be prohibited iff they refer to some additonal built in member
- override must be prohibited iff all of the overridden descriptors are additional

Other usages were able to be successfully compiled by 1.0.x

Solution with @Deprecated(level=Error) doesn't work properly, because
deprecation propagates to overridden, thus call 'java.util.ArrayList<String>().stream()'
becomes invalid, while it was correct in 1.0.x

 #KT-15794 Fixed
2017-01-19 10:20:35 +03:00
Denis Zharkov 22ddfed911 Do not load PlatformDependent annotated built-in members with lv=1.0
#KT-15780 Fixed
2017-01-18 13:00:32 +03:00
Alexander Udalov 8499db1f42 Update JvmMetadataVersion to 1.1.3
This is needed because 1.1.2 binaries are considered pre-release (see
DeserializedDescriptorResolver), so it wasn't possible to compile
non-pre-release binaries with -language-version 1.0
2017-01-17 15:00:52 +03:00
Alexander Udalov 6ffa56b640 Move name sanitization utilities to module 'descriptors' 2017-01-12 11:24:23 +03:00