Commit Graph

222 Commits

Author SHA1 Message Date
Leonid Startsev 7c8c5b057f Extensible mechanism for plugin metadata during descriptor serialization
A mechanism that allows kotlinx.serialization plugin to preserve the
correct (program) order of properties after serializing/deserializing
descriptors to kotlin metadata, which is needed for correct and stable
json serialization of class hierarchies in incremental/multi-module scenario.
It uses protobuf extensions.
2020-06-01 17:48:16 +03:00
Alexander Udalov 7bb77e5672 Move JS binary version utilities to 'js.config'
This allows to replace dependency of 'util' on 'deserialization' with
dependency on 'descriptors'.
2020-03-28 21:30:06 +01:00
Alexander Udalov 8dd04789ad Remove obsolete InlineStrategy
Replace corresponding metadata property in js.ast with Boolean. This
allows to get rid of dependency of 'js.ast' on 'frontend'.
2020-03-28 21:30:03 +01:00
Alexander Udalov 953b461c53 Add new compiler errors and flags when JVM compiles against JVM IR
From now on, the old JVM backend will report an error by default when
compiling against class files produced by the JVM IR backend. This is
needed because we're not yet sure that the ABI generated by JVM IR is
fully correct and do not want to land in a 2-dimensional compatibility
situation where we'll need to consider twice more scenarios when
introducing any breaking change in the language. This is generally OK
since the JVM IR backend is still going to be experimental in 1.4.

However, for purposes of users which _do_ need to compile something with
the old backend against JVM IR, we provide two new compiler flags:
* -Xallow-jvm-ir-dependencies -- allows to suppress the error when
  compiling with the old backend against JVM IR.
* -Xir-binary-with-stable-api -- allows to mark the generated binaries
  as stable, when compiling anything with JVM IR, so that dependent
  modules will compile even with the old backend automatically. In this
  case, the author usually does not care for the generated ABI, or s/he
  ensures that it's consistent with the one expected by the old compiler
  with some external tools.

Internally, this is implemented by storing two new flags in
kotlin.Metadata: one tells if the class file was compiled with the JVM
IR, and another tells if the class file is stable (in case it's compiled
with JVM IR). Implementation is similar to the diagnostic reported by
the pre-release dependency checker.
2020-01-29 17:20:41 +01:00
Mikhail Zarechenskiy 0e90d538df FIC: propagate info about conversions for deserialized classes 2020-01-17 19:36:08 +03:00
Mikhail Zarechenskiy 0fdebdfeba Refactoring: move SamConversionResolverImpl to core module 2020-01-17 19:36:07 +03:00
Svyatoslav Kuzmich 7592048437 [JS] Support typeOf 2019-09-25 18:12:55 +03:00
Alexander Udalov b970a57adb Generate version requirement on inline functions since API version 1.4
The old compiler will crash if it tries to inline a function that's
passing a lambda parameter into the new parameter null check method
`Intrinsics.checkNotNullParameter` because that usage is not considered as
inlinable by the old compiler (it only knows about
`Intrinsics.checkParameterIsNotNull`). Therefore we require that these
functions can only be read by compilers of version 1.3.50 or greater.

 #KT-22275 Fixed
2019-08-12 16:09:23 +02:00
Roman Artemev af45e1c5dc [JS BE] Do not produce source mapping for fake KtElement
Fix [KT-26701], [KT-12935]
2019-07-17 10:21:34 +03:00
Anton Bannykh fadeac083f JS: fix reified T::class for primitive T (e.g. Int) (KT-32215 fixed) 2019-06-28 13:49:22 +03:00
Anton Bannykh 8ab9ef2afa JS: don't visit all descriptors on metadata serialization 2019-06-03 15:53:00 +03:00
Anton Bannykh c3170d1908 JS: cache metadata, grouped by package FQN 2019-05-28 23:33:17 +03:00
Anton Bannykh fc7fea4863 JS: make .meta.js the same as before 2019-05-28 23:33:17 +03:00
Anton Bannykh 145ca7b6a9 JS: merge proto parts as bytes 2019-05-28 23:33:17 +03:00
nikita.movshin 65244b4bea Update copyright.
Change the copyright from "JetBrains s.r.o." to
"JetBrains s.r.o. and Kotlin Project contributors"
Update only 2 lines copyright.
2019-04-23 20:09:22 +03:00
Alexander Udalov 584137121b Do not write version requirements in metadata for lambdas
#KT-29790 Fixed
2019-03-12 18:53:08 +01:00
Anton Bannykh 4b39e2df12 JS: (review fix) Header -> InlineData 2019-02-14 15:14:28 +03:00
Anton Bannykh a35fc4fa3c JS: use string table for module names and inline function tags 2019-02-14 15:14:28 +03:00
Anton Bannykh d7499363bc JS: review fixes 2019-02-14 15:14:28 +03:00
Anton Bannykh 299a45ccbf JS: validate AST when serializing to IC cache 2019-02-14 15:14:28 +03:00
Anton Bannykh 52b705e7ae JS: Fix local aliases
Local aliases can be copied as-is to a different fragment now. Before this change we would have had to extract the local alias tag (if any) from the source fragment and add to the destination fragment name bindings.
2019-02-14 15:14:28 +03:00
Anton Bannykh c1fbeeb7d9 JS: fix bugs 2019-02-14 15:14:28 +03:00
Anton Bannykh a30c7fbee1 JS: Support imported wrapper serialization 2019-02-14 15:14:28 +03:00
Anton Bannykh 2cbdc7ecb0 JS: store whole JsImportedModule's in the module local alias
Module references were stored as plain JsName's. When inlining a function
from one fragment to another, those references should be re-interpreted
in terms of the destination fragment. Storing the whole module information
makes that much easier.
2019-02-14 15:14:28 +03:00
Anton Bannykh 6d26bf9622 JS: don't load binary AST unless required by the inliner 2019-02-14 15:14:28 +03:00
Anton Bannykh c65383fa3f JS: postpone JS AST merging 2019-02-14 15:14:28 +03:00
Anton Bannykh 3529114913 JS: incremental translation of tests and main fun invocation 2019-02-14 15:14:28 +03:00
Mikhael Bogdanov a122cba862 Switch Kotlin project to jvm-target 1.8
#KT-29405
2019-01-31 07:43:05 +01:00
Sergey Rostov 0f2fb4ff82 Build: remove intellijCore/annotations.jar usages 2019-01-28 13:43:08 +03:00
Dmitry Savvinov a4d1a8f60a Get rid of FUNCTOR slice, use lazy value in ContractDecription instead
Functor is an imperative representation of function's contract (contrary
to ContractDescription, which is a declarative one). ContractDescription
is convenient when we deal with sources of contracts declarations
(binaries, source), while Functors are convenient for analyzing code
with contracts.

It means that we have to convert ContractDescription into Functor when
we start working with contracts. This computation isn't trivial, and
Functor and ContractDescription are in 1-1 correspondence, so we would
like to cache Functor for each ContractDescription somewhere.

We used to do this in binding trace, in slice FUNCTOR.

Now, it turns out that this approach causes "Rewrite at slice"
exception, see KT-28847. We won't go into details of why that happens
here, you can see the issue comments for details (but be prepared for the
very long and nitty-gritty story)

This commit removes the problematic slice and introduces another
approach, where Functor is attached to the ContractDescription, computed
lazily and cached here.

^KT-28847 Fixed
2019-01-14 11:11:03 +03:00
Sergey Rostov 883970fadb Add explicit dependencies to nullable annotations 2018-12-26 09:07:06 +03:00
Pavel Punegov fe0a2bc75e Provide SerializerExtension methods with child DescriptorSerializer instance
to make Native be able to serialize backing properties and inline bodies.
Change visibility for functions and properties of DescriptorSerializer.
2018-11-26 18:15:30 +03:00
Alexander Udalov 1ee1d15b91 Support annotations on property accessors in JS/common metadata
#KT-14529 Fixed
2018-10-24 18:17:12 +02:00
Alexander Udalov 009f18f1f4 Split AnalysisFlag values to AnalysisFlags and JvmAnalysisFlags
Declare AnalysisFlags in module 'frontend', and JvmAnalysisFlags in
module 'frontend.java', to avoid leaking Java-related logic to common
compiler code
2018-10-01 13:31:00 +02:00
Alexander Udalov 871b896a21 Add internal compiler argument to change metadata version
Will be used in tests to check how we behave on binaries produced by a
"future" compiler
2018-07-18 17:59:37 +02:00
Alexander Udalov cfc0f5e453 Support correct way of writing/loading version requirement table
Tests are added in subsequent commits.

KT-25120 Fixed
2018-07-18 17:59:37 +02:00
Alexander Udalov 4122021090 Add BinaryVersion to DeserializationContext
This will be useful to implement version-dependent deserialization,
which is needed for gradual fixes of issues in metadata

 #KT-25120 In Progress
2018-07-18 17:58:46 +02:00
Alexander Udalov 1e9694f1db Fix version requirement serialization for nested classes
Use the version requierement table of the outer DescriptorSerializer
instance when serializing metadata for a class. Pass parent serializer
to DescriptorSerializer.create to make sure the correct table is used.
Serialize nested classes before the outer class in JS and common code,
to make sure requirements are not lost. Also, split
VersionRequirementTest to JVM and JS

 #KT-25120 In Progress
2018-07-18 17:58:46 +02:00
Alexander Udalov ae6627fe94 Simplify code in JS serialization related to module descriptors
Do not use `JsModuleDescriptor<...>` where only its `data` is needed
2018-07-17 20:26:31 +02:00
Alexander Udalov 77405b2cca Reformat module 'js.serializer' 2018-07-17 20:26:31 +02:00
Mikhael Bogdanov e00b7a993f Write version requirements for @JvmField in interface companion 2018-07-16 16:13:18 +02:00
Mikhael Bogdanov b412c90cef Move version requirements serialization for @JvmDefault to JvmSerializerExtension 2018-07-16 16:13:17 +02:00
Anton Bannykh 4872c97929 JS: enable release coroutines 2018-07-10 13:11:39 +03:00
Alexander Udalov 1951d38f40 Retain optional expected annotations when compiling platform code
After this change, optional expected annotations will be compiled to
physical class files on JVM, and stored to metadata on other platforms,
to allow their usages from dependent platform modules. For example:

    @OptionalExpectation
    expect annotation class A

When compiling this code on JVM, A.class will be produced as if the
class A did neither have the 'expect' modifier, nor had it been
annotated with OptionalExpectation. Note that if there's no actual
annotation class for A, then usages (which can only be usages as
annotation entries) are simply skipped.

Class A will be public from Kotlin's point of view (since it should
be possible to use it in Kotlin sources), but _package-private_ in Java
to disallow its usages outside of the declaring module.

 #KT-18882 Fixed
 #KT-24617 Fixed
2018-06-26 10:23:55 +02:00
Alexander Udalov 9309570752 Fix serialization of type parameters inner generic class
The call to `createTopLevel` instead of `create` (which creates
serializers for outer classes properly, with correct type parameter
contexts) caused MetadataSerializer to write type parameter metadata
incorrectly.  For example, in the following case:

    class A<E> {
        inner class B<T, E> { ... }
    }

A's type parameter E would get id 0, and B's type parameters T and E
would get ids 0 and 1. This is a problem because ids are supposed to be
unique for each class including its outer classes, and deserializer,
decompiler and stub builder rely on this assumption.

JVM metadata is unaffected because `create` is called correctly there,
see MemberCodegen#generateKotlinClassMetadataAnnotation

 #KT-24944 Fixed
2018-06-21 14:45:45 +02:00
Denis Zharkov 01a2330a70 Avoid retaining protobuf package within DeserializedPackageFragmentImpl
It's only used for DeserializedPackageMemberScope that's being created
during initialization

At the same time, protobuf objects may be not very light-weight
(see 2e933a165a)

 #KT-24513 Fixed
2018-06-08 17:49:40 +03:00
Denis Zharkov 0a3e8fbe66 Pull down some implementation details from DeserializedPackageFragment
- DeserializedPackageFragmentImpl doesn't actually need member scope to be lazy
in a sense of optimization. It was only necessary for breaking
initialization cycle: DeserializationComponents <-> DeserializedPackageFragment
- For MetadataPackageFragment it might be useful to have
member scope actually lazy since it has O(n) complexity when n is a number
of package parts

This change is helpful for avoidance of storing reference to package-proto

 #KT-24513 In Progress
2018-06-08 17:49:40 +03:00
Alexander Udalov 965e3ebab2 Do not serialize SOURCE-retained annotations
Also, fix the value of "hasAnnotations" flag to reflect if there are any
_non-source_ annotations on a declaration.

Unfortunately, after this change
IncrementalJsCompilerRunnerTestGenerated$PureKotlin.testAnnotations
starts to fail because of the following problem. The problem is that
annotations on property accessors are not serialized yet on JS (see
KT-14529), yet property proto message has setterFlags field which has
the hasAnnotations flag. Upon the full rebuild of the code in that test,
we correctly write hasAnnotations = true, but annotations themselves are
not serialized. After an incremental build, we deserialize property
setter descriptor, observe its Annotations object which happens to be an
instance of NonEmptyDeserializedAnnotationsWithPossibleTargets. Now,
because annotations itself are not serialized, that Annotations object
has no annotations, yet its isEmpty always returns false (see the code).
Everything worked correctly before the change because in
DescriptorSerializer.hasAnnotations, we used Annotations.isEmpty and the
result was the same in the full rebuild and in the incremental scenario.
But now we're actually loading annotations, to determine their
retention, and that's why the setterFlags are becoming different here
and the test fails

 #KT-23360 Fixed
2018-04-23 18:42:33 +02:00
Alexey Tsvetkov 8a82c1618c Use Plugins DSL in Kotlin Gradle scripts
When plugins DSL is used, there is no need to
manually generate typesafe accessors for extensions and
conventions (by running `./gradlew kotlinDslAccessorsSnapshot`).
2018-03-26 16:09:29 +03:00
Alexey Tsvetkov 2584143e92 Report correct source to output mapping for kjsm files
Now IC can correctly remove kjsm files when source files are changed
2018-03-19 18:04:33 +03:00