Commit Graph

118 Commits

Author SHA1 Message Date
pyos 1fe7ef6521 JVM: separate the two kinds of source mappers
* a writing source mapper has `mapLineNumber(line, file, class)` that
   inserts a new SMAP entry and returns a fake line number from it;
 * a copying source mapper has `mapLineNumber(line)` that uses an
   existing SMAP to resolve the line number and call the former method
   on a different source mapper;
 * those two types are disjoint.
2020-05-19 18:33:27 +02:00
Alexander Udalov a0400f59c2 Add -Xskip-prerelease-check compiler argument
#KT-38070 Fixed
2020-05-07 13:24:26 +02:00
Kevin Bierhoff 7448761dfd only stub default constructor when compiling against .java source files 2020-04-07 17:48:39 +02:00
Mikhail Zarechenskiy 8fdc39ecbc Update test data due to using stdlib with a pre_release flag
The problem here is that we have separate bootstrap compiler and
 artifacts (stdlib, for example) that are used in tests and implicitly
 participate in them.

 For example, this test started to fail when bootstrap compiler was
 advanced to a version where pre_release flag is enabled. As a result,
 dependent stdlib become pre_release as well and now we have additional
 error about `Unit` type
2020-03-10 17:22:26 +03:00
Mikhail Zarechenskiy d169435300 Fix construction of Mock classes in case of generic inner types
This fixes testMissingDependencyConflictingLibraries for NI and also
 fixes changed test for OI as well
2020-02-20 12:34:35 +03:00
Alexander Udalov c08c3d4d9b Update JVM metadata version to 1.4.0 2020-02-06 17:22:02 +01:00
Pavel Kirpichenkov 87e0186334 Cleanup test checking legacy inline suspend
Move expected library compilation output to file.
^KT-36240 Fixed
2020-02-05 19:34:59 +03:00
Alexander Udalov 5e7343624b Update test data of wrongInlineTarget to 1.4 2020-02-05 13:09:53 +01:00
Pavel Kirpichenkov 5a04b7935e Add workaround for obsolete inline suspend integration test
Restore test data dropped in 7abd87d5, add specific output check
KT-36240
2020-01-29 21:41:07 +03:00
Pavel Kirpichenkov 913ed71863 Update error about unsupported language and API versions
Set first supported version to 1.3
Add property for oldest depecated language version in order to control unsupported ones
Report error on attempts to manually disable language feature from unsupported versions
Update test data, drop compatibility tests for features from unsupported versions

KT-36146 In progress
2020-01-29 21:40:44 +03: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
pyos e54ef3bdb8 PSI2IR: ignore enum annotation arguments of error type
Similar to references to error type, this may happen if library A uses
an entity from library B annotated with an annotation from C, but A is
compiled without C on the classpath.
2019-12-26 10:10:29 +03:00
Ilmir Usmanov a1448ebb37 JVM_IR: Support crossinline suspend lambdas
The main idea is the following: since we need to generate
(fake)continuations before inlining, we move IrClasses of suspend
lambdas and continuation classes of named functions into the functions.
Thus, it allows the codegen to generate them prior to inlining and
the inliner will happily transform them for us.
Because of that, lowerings which transform call-site function are likely
to change reference to lowered suspend lambdas or functions.
Hence, do not rely on references to lowered suspend lambdas or
functions, instead, rely on attributes.

Do not generate continuation for inline suspend lambdas.
Previously, inline suspend lambdas were treated like suspend functions,
thus we generated continuations for them. Now we just do not treat them
as suspend functions or lambdas during AddContinuationLowering.
We should add continuation parameter to them, however.

Do not generate secondary constructor for suspend lambdas, otherwise,
the inliner is unable to transform them (it requires only one
constructor to be present).

Generate continuation classes for suspend functions as first statement
inside the function.
This enables suspend functions in local object inside inline functions.
Since we already have attributes inside suspend named functions, we
just reuse them to generate continuation class names. This allows us
to close the gap between code generated by old back-end and the new
one.

If a suspend named function captures crossinline lambda, we should
generate a template for inliner: a copy of the function without
state-machine and a continuation constructor call. The call is needed
so the inliner transforms the continuation as well.

Refactor CoroutineTransformerMethodVisitor, so it no longer depends on
PSI.
2019-12-23 18:03:40 +01:00
Pavel Kirpichenkov 55b3637f03 Fix case of inner object usage in missing supertypes checker
FakeCallableDescriptorForObject instance, which is not ConstructorDescriptor,
is checked with call checkers when object's contents are being used.
Checker of missing supertypes should not be run against this fake descriptor.
Object's members belong to separate member scope, so their resolution doesn't
force containing class' supertypes evaluation. I.e. object's methods
may work fine even if some supertypes of containing class are missing.
2019-11-25 10:57:52 +03:00
Pavel Kirpichenkov 8c52bb4212 Add frontend checks for missing dependency supertypes
Call checker and declaration checker are used in order to preserve backward compatibility.
Attempt to use classifier usage checker was not good enouth,
since not all errors found with it would actually be reported before.
For example types and constructor calls don't cause supertypes to resolve,
so missing supertypes would not lead to errors in case they are the only use of class name.

Updated tests failing due to missing Java dependencies in superclasses.
2019-11-18 12:06:41 +03:00
Mikhail Glukhikh 91a58fffb8 Add CLI test for K/javac project with non-transitive dependency, KT-33932 2019-10-18 12:29:05 +03:00
Alexander Udalov 0c939d2f86 Use correct class file version when copying anonymous objects in inliner
Generally, using state.classFileVersion would be enough because we
report an error when inlining bytecode into a class file with a lower
target version (see INLINE_FROM_HIGHER_PLATFORM). However, we take maxOf
with the original version of the class file, _just in case_ the user has
suppressed this error (for example, to workaround some other corner case
in the compiler).

 #KT-30744 Fixed
2019-10-08 13:44:40 +02:00
Alexander Udalov 59186b2617 Psi2ir: ignore unresolved class literals in annotations
Similarly to 38536638, skip annotation arguments that reference classes
which are not found in our compilation classpath.

This fix is especially needed because of the way _nested_ classes are
currently referenced in annotations. Since we don't generate all needed
InnerClasses attributes yet (KT-27936), we can't unambiguously resolve a
reference to a nested class in annotation arguments. This leads to an
ErrorValue loaded in the annotation descriptor. The old backend doesn't
care, since it doesn't look at that annotation or its arguments, but
psi2ir tries to convert all annotation arguments and it crashed with CCE
here, trying to cast IrErrorType to IrSimpleType.
2019-09-18 14:05:28 +02:00
Alexander Udalov 385366384c Psi2ir: ignore unresolved annotations
Note that the test is an exact copy of an existing test
missingDependencyNestedAnnotation, but with -Xuse-ir
2019-07-15 18:40:00 +02:00
Ilmir Usmanov dc821a720b Fix test data 2019-04-18 01:13:01 +03:00
Ilmir Usmanov 3724e05b63 Fix test data 2019-03-28 22:21:25 +03:00
Mikhael Bogdanov a020170a92 Report missed INLINE_FROM_HIGHER_PLATFORM diagnostic for derived class
Inline function descriptor in derived class represented as FAKE_OVERRIDE.
 So we should find it in base class declaration
 (not interface cause inline function can't be virtual, but always final)
 and then check class version.

 #KT-29402 Fixed
2019-02-19 10:51:36 +01:00
Ilmir Usmanov e21159c28f Report suspension point in monitor error on crossinline lambdas
#KT-27258: Fixed
2018-10-12 14:21:42 +03:00
Ilmir Usmanov 9af7316845 Add call checker to report error more granulary if possible
This, however, works only for calls of 'synchronized' only. Thus, it
does not support inline functions of any kind.
2018-10-09 22:55:51 +03:00
Ilmir Usmanov 281f09f077 Rework check of suspension point inside critical section
There is a trade-off between robustness of check and accuracy of the
diagnostic: the previous version, which works on generation, was too
fragile and lead to false-positives. Now we check on state machine
generation. However, since we do not have PSI for call, we can only
report diagnostic on whole suspend function or suspend lambda.
Additionally, the state machine is generated on crossinline suspend
lambdas regeneration and thus we do not have the PSI for the lambda as
well!

 #KT-27130 Fixed
 #KT-27258 Open
2018-10-09 22:55:48 +03:00
Ilmir Usmanov 2dd5b8fa70 Forbid suspension points in critical sections
#KT-26480: Fixed
2018-09-17 19:29:51 +03:00
Alexander Udalov 1d5d6b5b72 Support strict metadata version semantics
Preface: Kotlin 1.3 will be able to read metadata of .class files
produced by Kotlin 1.4 (see KT-25972). Also, to simplify implementation
and to improve diagnostic messages, we're going to advance JVM metadata
version to 1.4.0 in Kotlin 1.4, and would like to keep it in sync with
the compiler version thereafter. This presents a problem: in an unlikely
event that before releasing 1.4, we find out that the metadata-reading
implementation in 1.3 was incorrect, we'd like to be able to fix the bug
in that implementation and _forbid_ 1.3 from reading metadata of 1.4.
But prior to this commit the only way to do this was to advance the
metadata version, in this case to 1.5, and that breaks the
metadata/compiler version equivalence we'd like to keep.

The solution is to add another boolean flag to the class file, called
"strict metadata version semantics", which signifies that if this class
file has metadata version 1.X, then it can only be read by the compilers
of versions 1.X and greater. This flag effectively disables the smooth
migration scenario proposed in KT-25972 (as does increasing metadata
version by 2), and will be used only in hopeless situations as in the
case described above.
2018-09-10 14:12:18 +03:00
Dmitry Savvinov b064c48f83 Fix testdata after advancing LATEST_STABLE to 1.3
This commit contains minor changes in testdata, where test and behavior
change are not related
2018-08-30 16:24:31 +03:00
Denis Zharkov 66315cee45 Fix coroutine-related test data 2018-08-30 14:57:46 +03:00
Denis Zharkov 3a7f8dcf3a 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-30 14:57:41 +03:00
Alexander Udalov 9f4c8d5b81 Minor, fix test data
Language version 1.3 is no longer experimental
2018-08-30 14:57:35 +03:00
Alexander Udalov 02a9b03007 Report a warning or error if an old language version or API version is used
#KT-25823 Fixed
2018-08-30 14:57:31 +03:00
Alexander Udalov 254d943e07 Fix some tests in compileKotlinAgainstCustomBinaries 2018-08-30 14:57:07 +03:00
Alexander Udalov f6571effcc Do not report pre-release errors if release LV is used in pre-release compiler
This commit effectively reverts
d386712903.

The reason is that when using a release language version, you can only
"see" the subset of a pre-release library which consists of released and
supported features, so reporting an error is not helpful there. Also, it
presents a problem currently when using kotlinc 1.3 (which is
pre-release) with language version 1.2 (stable) against the bundled
stdlib of version 1.3 (pre-release)

 #KT-21267 Declined
2018-08-23 16:50:48 +02:00
Alexander Udalov 852760b3b0 Report error on incompatible .kotlin_module files in classpath
Also remove obsolete test wrongAbiVersionNoErrors

 #KT-25973 Fixed
 #KT-26266 Open
2018-08-21 17:12:02 +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
Dmitry Petrov b5f37d18b2 Fix inlining of functions with matching JVM signatures in same package
When two functions with matching JVM signatures in the same package
were inlined sequentially, inliner could take a wrong method body from
the cache due to MethodId clash. This manifested with inline classes,
but also was possible with some legal Kotlin overloads with matching
erasure.

Use internal name of the corresponding implementation owner class
instead of FQN of the containing declaration. Such MethodIds can't match
accidentally, because corresponding JVM method signatures would clash.
2018-08-20 14:12:34 +03:00
Alexander Udalov c011bf61fe Support multiple version requirements on single element 2018-08-13 11:02:35 +02:00
Alexander Udalov 1a51132884 Add CLI tests on internal from other module (JVM, JS, common) 2018-07-27 18:51:42 +02:00
Alexander Udalov 4bd66d5aa8 Add compiler argument -Xfriend-paths for kotlinc-jvm
#KT-21910 Fixed
2018-07-27 18:51:42 +02: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 5fbe35d1c8 Add tests on RequireKotlin on nested classes with metadata version 1.4 2018-07-18 17:59:37 +02:00
Alexander Udalov ea3c5c0107 Use -Xmetadata-version in tests instead of custom preprocessing
Test data for the wrongMetadataVersion test has changed because now not
only the .class files have the "future" version, but also the
.kotlin_module file, which prevents the current compiler from being able
to read what parts does a package in the library consist of. This is
related to the TODO in ModuleMapping.kt:89
2018-07-18 17:59:37 +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
Dmitry Petrov 5767f84c0e Restrict retention for annotations with target EXPRESSION
#KT-13762 Fixed
2018-07-18 14:21:03 +03: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 03c50ea139 Add test for calling release coroutine from experimental one 2018-07-11 14:20:44 +03:00
Mikhail Glukhikh e76debb12b Report UNUSED_PARAMETER in setter #KT-21129 Fixed 2018-05-04 18:04:57 +03:00
Mikhail Zarechenskiy 9e22761262 Fix type parameters indexes of MockClassDescriptor
Exception was thrown during mapping of arguments to parameters in `computeSupertypeProjections`

 #KT-18522 Fixed
2018-02-11 16:21:23 +03:00
Alexander Udalov 82574cb570 Do not store ClassDescriptor in EnumValue
Only store the ClassId of the enum class and the Name of the entry, and
resolve the needed descriptor in getType() instead, which now takes the
module instance where that descriptor should be resolved
2018-01-18 12:49:38 +01:00