Commit Graph

437 Commits

Author SHA1 Message Date
Alexander Udalov ed86757817 Rework how built-in types are loaded in compiler for JVM
In TopDownAnalyzerFacadeForJVM, we now always use the "load built-ins
from module dependencies" behavior that was previously only enabled with
the dedicated CLI argument -Xload-builtins-from-dependencies. However,
sometimes we compile code without kotlin-stdlib in the classpath, and we
don't want everything to crash because some standard type like
kotlin.Unit hasn't been found.

To mitigate this, we add another module at the end of the dependencies
list, namely a "fallback built-ins" module. This module loads all
built-in declarations from the compiler's class loader, as was done by
default previously. This prevents the compiler from crashing if any
built-in declaration is not found, but compiling the code against
built-ins found in the compiler is still discouraged, so we report an
error if anything is resolved to a declaration from this module, via a
new checker MissingBuiltInDeclarationChecker.

Also introduce a new CLI argument -Xsuppress-missing-builtins-error
specifically to suppress this error and to allow compiling code against
compiler's own built-ins.

 #KT-19227 Fixed
 #KT-28198 Fixed
2019-03-22 14:59:03 +01:00
romanart 5b5f3a7468 [IR] Fix classes TypeParameter [de]serialization 2019-03-20 11:57:57 +03:00
Mikhail Zarechenskiy 892fb9f39e Increment metadata version and improve message for error type
Follow-up of 617bed1b
2019-02-27 14:03:22 +03:00
Sergey Rostov f35185b261 Build: remove explicit dependencies to org.jetbrains.annotations 2019-01-28 13:43:08 +03:00
Sergey Rostov 883970fadb Add explicit dependencies to nullable annotations 2018-12-26 09:07:06 +03:00
Sergey Rostov df2e4524d7 Move resources from /src to separate /resources directory.
Previously this files was stored in /src directory and was included in
resources mainly by SourceSet.projectDefault from sourceSets.kt:

val processResources = tasks.getByName(processResourcesTaskName) as ProcessResources
processResources.from("resources") { include("**") }
processResources.from("src") { include("META-INF/**", "**/*.properties") }

Also there are some custom rules like this:

resources.srcDir("../idea-analysis/src").apply { include("**/*.properties") }
resources.srcDirs("idea-repl/src").apply { include("META-INF/**") }

All this rules are synthesized in script
https://github.com/snrostov/kotlin-migrate-resources/blob/master/src/main/kotlin/main.kt

This commit created using that script. See README.md for more details on
 script.
2018-11-30 15:01:01 +03:00
Mikhail Glukhikh 8035be07e2 FIR: built-in resolve, preliminary version #KT-24091 Fixed 2018-11-02 19:44:55 +03:00
Alexander Udalov c1ab08c8ce Refactor KClassValue to store ClassLiteralValue internally
Only invariant array projections and non-null element types will be
supported soon (see KT-26568), so it makes no sense to store the
complete type in KClassValue. What we need is only the ClassId of the
class, and the number of times it's wrapped into kotlin/Array, which is
exactly what ClassLiteralValue represents.

This change helps in decoupling annotation values from
descriptors/types. The only constant value that depends on descriptors
is now AnnotationValue.

 #KT-26582 Fixed
2018-10-25 16:27:23 +02:00
Alexander Udalov 1ee1d15b91 Support annotations on property accessors in JS/common metadata
#KT-14529 Fixed
2018-10-24 18:17:12 +02:00
Denis Zharkov 956f8ad5e9 Support deserialized contracts in common code
#KT-26687 Fixed
2018-09-17 12:48:42 +03:00
Denis Zharkov 9cb8a35275 Minor. Pull user-data related things to CallableDescriptor
Currently, we assume user data for all non-FunctionDescriptor
declarations is empty
2018-09-12 09:49:25 +03:00
Alexander Udalov ab3f8db743 Consider property accessor non-default if it has annotations
Otherwise we're not trying to load annotations on the parameter of the
property setter in MemberDeserializer.loadProperty.

Note that after this commit, we could now also assume that if
getter/setter is default, it has no annotations, and thus use
Annotations.EMPTY for default getter/setter in loadProperty. However,
this would cause reflection to work incorrectly on classes compiled by
an older Kotlin compiler, so we'll still try to load annotations on
default accessors for an indefinite time.

 #KT-25499 Fixed
2018-09-07 11:49:42 +03:00
Alexander Udalov 06ce0cb0f0 Fix deserialization of default property accessor flags
In MemberDeserializer.loadProperty, we incorrectly passed 0 to
getAnnotations when loading annotations on property accessors in case
the protobuf field getter_flags/setter_flags was not present. The
correct behavior, as described in metadata.proto, was to pass a special
"default accessor flags" value, constructed from the main property
flags. Otherwise in case there were annotations both on the property and
on the accessor (as in PropertyAndAccessor.kt) and the accessor was
otherwise default, we would assume that it had no annotations and would
not load them in compiler and reflection

 #KT-25499 In Progress
2018-09-07 11:49:41 +03:00
Alexander Udalov a432704c4f Fix typo in MemberDeserializer.loadProperty when loading inline setters
This could lead to inline setters of properties which have default
getters not being inlined
2018-09-07 11:29:16 +03:00
Ilmir Usmanov 94096bba26 Ignore version requirements of kotlin.suspend completely 2018-09-07 01:03:53 +03:00
Alexander Udalov 7658ddafd8 Make AnnotationsImpl internal, introduce Annotations.create 2018-09-06 19:13:17 +03:00
Alexander Udalov c0b025b23d Provide default implementation for Annotations.getUseSiteTargetedAnnotations
After this commit, it's overridden only in AnnotationsImpl and
CompositeAnnotations.

Note that although FilteredAnnotations did have a non-trivial
implementation, that class was only used in circumstances where
annotations with use-site targets could not be of any use, so it's safe
to return empty list there now. One could argue that the new semantics
makes more sense: filter "standard" annotations, but don't touch those
with use-site targets because they are not applied to this element
directly, thus should likely not be affected by the filtering
2018-09-06 19:13:16 +03:00
Alexander Udalov 98232265d7 Simplify deserialization of annotations on backing/delegate fields
Instead of returning the list of targeted annotations in
loadCallableAnnotations, add two separate methods to load annotations on
the backing field and on the delegate field of the property
2018-09-06 19:13:15 +03:00
Alexander Udalov 87c0d56618 Drop Annotations.getAllAnnotations 2018-09-06 19:13:14 +03:00
Alexander Udalov fc87043cb3 Merge use-site targeted annotations into corresponding Annotations
Add PropertyDescriptor.backingField/delegateField to store annotations
on the field directly in an otherwise almost empty descriptor instance,
instead of storing them with use-sites in the corresponding property
descriptor. Instead of AnnotationWithTarget, create AnnotationDescriptor
instances in AnnotationSplitter. Change DescriptorRenderer to render
annotations on "related" declarations when needed, with the explicit
use-site target if applicable.

Most changes in diagnostic test data are related to the fact that
annotations which are known to have an incompatible use-site to the
declaration they're applied at (such as `@param:`-annotation on a
function), are now not loaded at all. It's fine because the code is
erroneous, so it doesn't really matter how do we load annotations with
invalid targets (some of this logic is also changed freely in subsequent
commits). Some changes are also explained by the fact that for example
an annotation on the property which is only applicable to FIELD is now
rendered with an explicit use-site target `@field:`, regardless of
whether it did have that use-site target syntactically or not.

Basically, after this change there's no point in calling
Annotations.getUseSiteTargetedAnnotations/getAllAnnotations anymore
because it's easier and more intuitive to just use Annotations of the
corresponding descriptor -- the backing / delegate field (introduced in
this commit) or the extension receiver / setter parameter (related
behavior was fixed in previous commits). Usages of
use-site-target-related methods will be refactored out in subsequent
commits
2018-09-06 19:13:11 +03:00
Alexander Udalov 0e5544a491 Use AnnotationSplitter for annotations on extension receiver
Instead of using `@receiver:`-targeted annotations on the receiver type,
use normal annotations of the ReceiverParameterDescriptor instance
everywhere
2018-09-06 19:13:10 +03:00
Alexander Udalov 823a24e0a3 Use AnnotationSplitter for annotations on setter parameter
Make it possible to specify annotations of the setter parameter when
constructing the default setter via DescriptorFactory; pass the split
annotations in DescriptorResolver.resolvePropertySetterDescriptor

 #KT-25500 Fixed
2018-09-06 19:13:09 +03:00
Alexander Udalov f90303315d Support array class literals in annotation serializer/deserializer
Note that this change brings an incompatibility: `Array<Foo>::class`
will be seen as `Foo::class` by the old deserializer. We consider this
OK because the compiler never had any logic that relied on reading class
literal arguments correctly (otherwise it wouldn't have worked because
it could only see `Array<*>::class` before this commit), and the support
of annotations on types in JVM reflection is only available in the
upcoming 1.3 release (KT-16795)

 #KT-22069 Fixed
2018-09-06 14:40:06 +03:00
Alexander Udalov ab441dcd96 Drop PropertyDescriptorImpl.setType that takes KotlinType
Only use the other setType that takes an instance of
ReceiverParameterDescriptor. This will make sure that call sites can
use correct receiver annotations
2018-08-27 23:37:05 +02:00
Alexander Udalov 34c033bcaf Take ReceiverParameterDescriptor in FunctionDescriptorImpl.initialize
Instead of just KotlinType. This will allow to pass annotations on the
receiver at call sites
2018-08-27 23:37:04 +02:00
Denis Zharkov 944b0d058a Allow calling some pieces of the experimental coroutine API
- Calling suspend functions is allowed
- Presence of suspend function type still makes declaration
unusable unless it belongs to a value parameter as a top-level type
containing less then three parameters

Still, warning should be emitted because they will become unsupported in 1.4

 #KT-25683 In Progress
2018-08-21 13:44:02 +03:00
Alexander Udalov 92e7fe347a Minor, provide more info when deserializing bad constant value 2018-08-17 16:31:54 +02:00
Alexander Udalov ac0f5548aa Only check language version in MemberDeserializer.loadAsSuspend
This is still not 100% foolproof because one may place such a
requirement manually on a suspend function (with `@RequireKotlin`, for
example), which will trick the compiler into thinking that this is a new
suspend function, even if it was compiled with old coroutines. But it's
still better than only checking the version number
2018-08-13 11:02:36 +02:00
Alexander Udalov c011bf61fe Support multiple version requirements on single element 2018-08-13 11:02:35 +02:00
Ilmir Usmanov a10bd9f5a3 Refactoring. Move transformRuntimeFunctionTypeToSuspendFunction to TypeDeserializer 2018-07-25 15:35:13 +03:00
Ilmir Usmanov 533dd44668 Refactoring. Make DeserializedMemberDescriptor somewhat immutable 2018-07-25 15:35:09 +03:00
Ilmir Usmanov fa9653c3d2 Deserialize experimental coroutines as suspend functions/types
but deprecate them for now.
Promote stub version.
 #KT-25623: Fixed
2018-07-23 21:52:17 +03: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 53a57e8e1b Reformat module 'deserialization', fix warnings/inspections 2018-07-17 20:26:31 +02:00
Ilmir Usmanov 6ba2baa9da Deserialize constructors and properties with version requirement 1.3
if they have suspend function type in their descriptors.
Also, review fixes.

 #KT-25256: Fixed
2018-07-11 14:20:46 +03:00
Ilmir Usmanov 524cc3ffe4 Forbid old coroutineContext deserialization. Fix suspend function deserialization 2018-07-11 14:20:43 +03:00
Ilmir Usmanov 5b7e099842 Read old suspend functions in 1.3 2018-07-11 14:20:41 +03:00
Alexander Udalov 2cb4b7c6d4 Extract MetadataPartProvider out of PackagePartProvider 2018-07-10 15:16:49 +02:00
Mikhail Zarechenskiy 0c6757a8b0 Write is_unsigned flag into metadata for an annotation arguments
Instead of adding new kind of types, we'll use flag to disambiguate
 usual types from unsigned ones, this approach has two advantages:
 - less changes in the metadata format
 - it allows naturally extend format for unsigned arrays,
  which will be supported later

 #KT-25310 Fixed
 #KT-25273 Fixed
2018-07-09 20:06:05 +03:00
Alexander Udalov 959c2f4843 Get rid of split packages in descriptors, descriptors.jvm, deserialization
Also move some other files to related packages and reformat moved files
2018-07-06 14:08:35 +02:00
Denis Zharkov a644cbb5ed Fix deserialization of kotlin.suspend when LV=1.3 is used
Before this change, kotlin.suspend was being loaded as having a common
function type instead of suspend function type.

With LV=1.3, we expect that suspend function types should have
new Continuation interface as a last type argument, while
kotlin.suspend is built with LV=1.2 and has old Continuation.

This change might be reverted once stdlib will be rebuilt with LV=1.3

NB: kotlin.suspend doesn't need to be intrinsified since it only returns
its parameter with checkcast to kotlinin.jvm.functions.Function1
(i.e., it doesn't refer the coroutines package)

 #KT-24861 Fixed
2018-06-21 16:02:13 +03:00
Denis Zharkov 3d3d21cb93 Minor. Extract function in TypeDeserializer 2018-06-21 16:02:13 +03:00
Denis Zharkov 9deb9473d2 Minor. Reformat TypeDeserializer.kt 2018-06-21 16:02:13 +03:00
Denis Zharkov 3fcf2f9c0d Minor. Move KOTLIN_SUSPEND_BUILT_IN_FUNCTION_FQ_NAME constant to 'core'
It will be used for deserialization of kotlin.suspend in the next commit
2018-06-21 16:02:13 +03: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 1b15619457 Move BinaryVersion to metadata, JVM versions to metadata.jvm
To be used in kotlinx-metadata
2018-05-16 17:16:22 +02:00
Alexander Udalov 7bac9b62c7 Reformat VersionRequirement and move to 'metadata' 2018-04-23 18:42:33 +02:00
Ilmir Usmanov 2cfe387bab Move coroutines to kotlin.coroutines package: compiler
Generate continuation type as kotlin.coroutines.Continuaion. This code will
fail at runtime since there is no stdlib backing this change yet.
However, in order to generate compatible stdlib we need a compiler, which
generates continuation type as kotlin.coroutines.Continuation.
Thus, firstly we support the change in the compiler, make it bootstrap
compiler and only then change stdlib and tests accordingly.
 #KT-23362
2018-04-10 22:51:46 +03:00