Commit Graph

8267 Commits

Author SHA1 Message Date
Simon Ogorodnik 82611ad124 FIR. BI: Fix stub type leakage in builder inference
Previously, updateTypeInBuilderInference was calling
updateTypeFromSmartcast to actually perform type update in
implicit receiver after stub types was inferred
Such action results in creation of following FIR:

FirSmartCastExpression(
    original=FQAE(FirImplicitThisReference, typeRef=R|Inv<Stub>|)
    typeRef=R|Inv<String>|
)

in receiver position during completion of calls

However, it wasn't the case in general situation due to
action of FirStubTypeTransformer, which, in turn visits and updates
type ref inside original expression, but only if there was at
least one call (that was completed) using that implicit receiver
As after such type update updateTypeFromSmartcast function does
nothing

Yet in situation, when there was only partially resolved calls
referencing that implicit receiver we actually create smart-cast
expression and don't update type

The change just removes usage of updateTypeFromSmartcast and
replaces is with direct type update
We still mutate state of implicit receiver, potentially
improperly, it should be addressed in future

^KT-54708
^KT-58365 Fixed
2023-05-04 12:46:28 +00:00
Pavel Punegov 3d65907b8c [K/N][test] Ignore test in Native K1
This test doesn't work with K1 in Native

Merge-request: KT-MR-9934
Merged-by: Pavel Punegov <Pavel.Punegov@jetbrains.com>
2023-05-04 08:50:42 +00:00
Ilya Gorbunov 568d4b11af Use 'run' function instead of 'synchronized' in KT-51036 test
It should be enough to reproduce the issue and makes the test runnable on all backends
2023-05-04 02:44:26 +00:00
Ivan Kylchik 7747643945 [IR] Filter chars and codePoints from allowed to interpret function
These two functions apparently are represented in Kotlin as methods
of `kotlin.String`. Because of that we accidentally treated them as
builtins.

To also minimize such cases, added filtration by return type. We are
allowing to interpret only these functions that have primitive or
unsigned return type.

#KT-57028 Fixed
2023-05-03 12:47:35 +00:00
Pavel Kunyavskiy af318fdfb0 [K/N] Fix default arguments in suspend functions
AddContinuationToFunctionsLowering was rewritten in way the order
of this lowering and defaults lowering doesn't matter.

^KT-58214
2023-05-03 12:14:53 +00:00
Dmitriy Novozhilov e9c8be3b64 [FIR] Don't generated fake-overrides for private declarations of actualized super classes
^KT-58252 Fixed
2023-05-02 10:24:53 +00:00
Dmitriy Novozhilov f7733e819d [FIR] Approximate captured types during approximation of local types
^KT-57222 Fixed
2023-04-30 15:58:32 +00:00
Alexander Udalov 4f66d5bb1c JVM: minor, change logic of anyAnnotationDisablesIndyLambdaGeneration.kt
Do not check that non-indy-generated lambdas inherit from Lambda,
because when we enable indy lambdas by default, we're also changing the
behavior of non-indy lambdas so that they won't have the Lambda
superclass anymore (see KT-45375). Since this test was added to check
that any annotation disables indy lambda generation, just leave those
lambdas and rely on the CHECK_BYTECODE_TEXT directive to verify that
there are no LambdaMetafactory in the bytecode text.
2023-04-28 21:34:19 +00:00
Alexander Udalov 4d7506bae3 JVM: enable indy lambdas in some tests explicitly
To simplify enabling of indy lambdas by default.
2023-04-28 21:34:19 +00:00
Alexander Udalov cd9209a7ee JVM: enable -Xlambdas=class in some codegen tests
Most of these tests check the specific structure of lambdas when they
are generated as classes, and they start to fail once invokedynamic
lambdas are enabled by default.
2023-04-28 21:34:19 +00:00
Alexander Udalov 163afc94bc JVM: prepare asmLike tests for indy lambdas by default
Use -Xlambdas=class in tests which were checking specific things related
to how anonymous classes for lambdas work (such as receiver mangling,
function arity etc.)
2023-04-28 21:34:19 +00:00
Dmitriy Novozhilov 15dfe6c750 [FIR2IR] Use signature instead of FIR as a key for fake-override storage
This is needed to correctly handle the case, when we have the same java
  class in common and platform module. In this scenario we have two
  different classes on frontend (because symbol providers are not shared)
  and completely different enhanced function in scopes of those classes,
  but exactly one IrClass for those classes, which is cached during
  conversion of common module together with cache of its fake overrides.
  So using FirDeclaration as a key to FO cache leads to the problem, when
  we can not find cached value for platform module, because it has different
  fir declarations for the same real decalration

^KT-58030 Fixed
2023-04-28 13:08:19 +00:00
Denis.Zharkov 7b46c59d57 K2: Complete property-candidate before starting invoke resolution
Before this commit, for property candidates in K2 their types wasn't
inferred/susbtituted properly.

So, when candidate for fooBar.liveLoaded.invoke() was created,
the type of `fooBar.liveLoaded` was just X type parameter for which
there is no any `bar()` functions in its member scope.

While proposed semantics is a bit different from K1, where
both property and invoke candidates are united into common system,
it doesn't contradict to the specification (https://kotlinlang.org/spec/overload-resolution.html#callables-and-invoke-convention)
which says explicitly that invoke-convention should be desugared as
`r.foo.invoke()`, thus `r.foo` should be completed independently.

Also, this strategy supports some reasonable use-cases like KT-58259
while it's still a breaking change but for more artificial-looking
situations (see KT-58260) and should be passed through
the language committee.

The changes in stubTypeReceiverRestriction* tests looks consistent
because of how `genericLambda` now works
(with full completion of property call).
NB: The code is going to be red once KT-54667 is fixed and also there's
already similar diagnostic in K1 (INFERRED_INTO_DECLARED_UPPER_BOUNDS)

^KT-58142 Fixed
^KT-58259 Fixed
^KT-58260 Related
2023-04-28 12:46:20 +00:00
Alexander Udalov fc0ce415d7 JVM: remove source code from not null assertion message text
This is implemented under a LanguageFeature which will be enabled later,
when behavior change described in KT-57570 is approved.

 #KT-57570
2023-04-28 10:26:15 +00:00
Dmitriy Novozhilov 7958a9debd [FIR2IR] Correctly generate delegating constructor call for secondary constructors in enums
^KT-56927 Fxied
2023-04-27 13:35:14 +00:00
Mikhail Glukhikh 08c22c388c K2: change logic of result type search in ILT case
Related to KT-57487, KT-57703
2023-04-27 12:19:38 +00:00
Mikhail Glukhikh 27c4a7b7ef FE: add new tests around unresolved integer literals
Related to KT-57487, KT-57703
2023-04-27 12:19:38 +00:00
Mikhail Glukhikh 70c5978add K2: Approximate ILT in vararg expressions properly #KT-57487 Fixed 2023-04-27 12:19:38 +00:00
Alexander Udalov 68b94b07b8 Fir2Ir: more precise calculation of enum class modality
Use the same condition as in the already existing `createIrEnumEntry`
function (and as in psi2ir): enum class should be final unless there's
an enum entry with any declaration other than its constructor.

 #KT-57216
2023-04-27 11:02:22 +00:00
Ilya Chernikov a045a0a81c FIR: use default getter in serializer if fir contains none
since we generate the default getter in this case in
Fir2IrDeclarationStorage.createIrProperty, so the serialized metadata
should follow the same behavior.
#KT-57373 fixed
2023-04-27 09:14:20 +00:00
Ilya Gorbunov f260b55810 Raise deprecation of js synchronized {} to error 2023-04-26 10:44:52 +00:00
Abduqodiri Qurbonzoda 63a5a74613 Introduce HexFormat for formatting and parsing hexadecimals #KT-57762
Merge-request: KT-MR-9460
Merged-by: Abduqodiri Qurbonzoda <abduqodiri.qurbonzoda@jetbrains.com>
2023-04-26 09:54:25 +00:00
mvicsokolova 75b4469757 [K/N] Stabilization of Atomics API
`AtomicInt`, `AtomicLong`, `AtomicReference` and `AtomicNativePtr` classes were moved to `kotlin.concurrent` package. The corresponding classes from `kotlin.native.concurrent` were deprecated with warning since Kotlin 1.9.

In order to prepare for further commonization of Atomics API the following changes were made:
* `kotlin.concurrent.AtomicInt`: 
    * `increment(): Unit` and `decrement(): Unit` methods were deprecated with error
    * New methods were added: `incrementAndGet(): Int` , `decrementAndGet(): Int`, `getAndIncrement(): Int`, `getAndDecrement(): Int`, `getAndSet(newValue: Int): Int` 
* `kotlin.concurrent.AtomicLong`:
    * `increment(): Unit` and `decrement(): Unit` methods were deprecated with error
    * New methods were added: `incrementAndGet(): Long`, `decrementAndGet(): Long`, `getAndIncrement(): Long`, `getAndDecrement(): Long`, `getAndSet(newValue: Long): Long`
    * Deprecated `AtomicLong()` constructor with default parameter value
* For all atomic classes `compareAndSwap` method was renamed to `compareAndExchange`

See KT-58074 for more details.

Merge-request: KT-MR-9272
Merged-by: Maria Sokolova <maria.sokolova@jetbrains.com>
2023-04-25 16:55:42 +00:00
Mikhail Glukhikh 1c56a71b14 FirClassSubstitutionScope: don't recreate constructor type parameters w/out need
#KT-58008 Fixed
2023-04-25 16:42:59 +00:00
Mikhail Glukhikh 5daafd5ed5 FirNestedClassifierScope: don't give empty map substitutor to a processor
Optimization related to KT-58008 (hides the issue in some cases)
2023-04-25 16:42:59 +00:00
Mikhail Glukhikh 4172ce1018 K2: reproduce KT-58008 2023-04-25 16:42:59 +00:00
Alexander Udalov 3120a35a88 JvmDefault: remove most tests on @JvmDefault
The tests are removed because JvmDefault is going to be deprecated with
error in KT-54746 and removed later in KT-57696.

Many of the removed tests already had existing counterparts with the new
modes `all` and `all-compatibility`. In this change, I've added such
tests where they were missing, and removed tests which were testing
behavior specific to the JvmDefault annotation, such as some
diagnostics.

 #KT-54746
2023-04-25 14:33:00 +00:00
Mikhail Glukhikh dc38ce24f7 K2: fix field annotation splitting and frontend checks
Related to KT-57135
2023-04-25 12:18:26 +00:00
Pavel Mikhailovskii 37ed7beda0 KT-57135 Take into account annotations' allowed targets
- Check allowed targets
- Attach field annotations to the backing field
2023-04-25 12:18:26 +00:00
Nikolay Lunyak 931894ab3c [FIR] KT-57655: Add the missing condition
^KT-57655 Fixed
2023-04-25 10:57:08 +00:00
Nikolay Lunyak c4d5332251 [FIR] KT-57655: Ensure the current IR is incorrect
The
`FirPsiBlackBoxCodegenTestGenerated.testImplicitIntegerCoercionNamedArg`
test fails in K2 with "java.lang.Integer
cannot be cast to kotlin.UInt".
2023-04-25 10:57:07 +00:00
Dmitriy Novozhilov 903e969598 [FIR2IR] Correctly calculate offsets for implicit toLong() calls during constant evaluation
^KT-58132 Fixed
2023-04-25 09:36:17 +00:00
Alexander Udalov f04d01cf21 JVM IR: fix behavior of Enum.entries for unlowered enums
#KT-57671 Fixed
2023-04-24 12:43:43 +00:00
Zalim Bashorov 77491ded1b Use Array constructor with size to create Array of nulls
Change the constructor visibility from public to private as it should be.
2023-04-22 17:41:23 +00:00
Svyatoslav Kuzmich 933f47aaf9 [Wasm] Rename JsHandle to JsReference
Decision to do this was made at Kotlin/Wasm interop design meeting
2023-04-21 15:03:20 +00:00
Ivan Kochurkin b72dcf8b37 [K2, MPP] Fix actualization of nullability-based overloads
^KT-58043 Fixed
2023-04-20 17:22:45 +00:00
Kirill Rakhman e80b4c530d [FIR2IR] Properly handle intersection types in interface delegation
The changes to the irText test data result in the fact that we
now unconditionally unwrap substitution overrides of delegation targets
whereas before we built an unsubstituted scope of the type we delegate
to. If we delegate to a class A : B<C>, the unsubstituted scope of
A can still contain substitution overrides for inherited generic methods
from B<T> that we didn't unwrap before but do unwrap now.

#KT-57899 Fixed
2023-04-20 08:12:55 +00:00
Kirill Rakhman 35c6da1aa7 [FIR2IR] Fix and refactor generation of dynamic call receiver generation
#KT-57988 Fixed
2023-04-20 08:04:07 +00:00
Ivan Kylchik 6b75b3bc4a [IR] Drop duplicated meta info from interpreters tests 2023-04-19 13:52:48 +00:00
Ivan Kylchik 3f60c83921 [IR] Add id method in interpreter's tests to avoid optimizations 2023-04-19 13:52:48 +00:00
Ivan Kylchik 621f5a0fb7 [IR] Reorganize test files in involvesIrInterpreter dir 2023-04-19 13:52:48 +00:00
Ivan Kylchik c00c7ffbe0 [K2] Use file name as one of parameters to extract evaluated const
It is not enough to store evaluated constants only by
<startOffset, endOffset> pair. We need to consider case there constant
can be located in different files with the same offset but with
different values.

#KT-57928 Fixed
#KT-57929 Fixed
2023-04-19 13:52:46 +00:00
Ivan Kylchik 8cc8e54a9f [IR] Extract toString interpretation test of float value into new file
We need to distinguish `toString` results for JVM and JS
2023-04-19 13:52:46 +00:00
Ivan Kylchik 1ddcdcfc39 [IR] Rewrite logic around object interpretation
Basically we want to allow object interpretation only when we try
to access some const val property.

#KT-57810 Fixed
2023-04-19 13:52:44 +00:00
Ivan Kylchik 5956e9b500 [IR] Print evaluated const directly into interpreter's tests 2023-04-19 13:52:44 +00:00
Ilya Chernikov 8cc9f911d5 FIR: temp: make klib symbol provider know parent packages
Current qualified access resolving algo rely (likely incorrectly,
see #KT-58037) on a providers' "knowledge" about parent packages.
This commit adds this "knowledge" to k-lib based provider.
#KT-57353 fixed
2023-04-19 11:42:03 +00:00
Pavel Mikhailovskii 3bb66e8432 KT-57714 Fix remapping of signatures with reified type parameters 2023-04-19 07:20:51 +00:00
Kirill Rakhman ff7072830f [FIR] Make lambda parameters of dynamic function calls dynamic
#KT-57961 Fixed
2023-04-18 13:43:45 +00:00
Alexander Korepanov 79d378f2bd [JS IR] Perform optimizations on the generated JS code
The patch adopts and reuses the optimizations from the legacy backend.

The optimizations remove useless temporary variables,
statements and simplify generated JS code.

The optimizations can be disabled by `-Xoptimize-generated-js=false`.

Related to KT-51139
2023-04-18 12:49:33 +00:00
Svyatoslav Scherbina 54c07f5ebb Ignore K2 expectPropertyAsDefaultArgument.kt test for K1/Native
It is not supposed to work with K1 on Native due to test infrastructure
limitations, and actually fails in one of the compilation modes in
nightly tests.
2023-04-18 10:43:51 +00:00