Commit Graph

95625 Commits

Author SHA1 Message Date
Mikhail Glukhikh 7bd512fbb3 FE: add test for KT-54305 2022-10-25 12:33:08 +00:00
Johan Bay 9f3d8130db Remove unnecessary deprecation annotation
Private members on private companion objects have proper visibility
so there is no need for the @Deprecated annotation.

^KT-54539 Fixed
2022-10-25 14:03:11 +02:00
Alexander Udalov b42a7be0de Psi2ir: keep nullability when substituting function type for SAM type
After we added "careful approximation of contravariant projections" in
584b70719e, some SAM conversions started to require an additional
implicit cast of the functional value before it is converted to the SAM
interface. The target type of this implicit cast was computed
incorrectly because it didn't contain nullability of the SAM type. This
could lead to a situation where a nullable value was incorrectly cast to
a non-null type, which caused a missing null check and NPE at runtime.

For example, let's consider the test `kt54600.kt`. SAM conversion
happens in the constructor call `J(filter)`. Before 584b70719e, the IR
for that argument was (irrelevant things are omitted for simplicity):

  TYPE_OP SAM_CONVERSION type=Condition<String!>!
    GET_VAR filter type=Function1<String, Boolean>?

After 584b70719e, the IR became:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>
      GET_VAR filter type=Function1<String, Boolean>?

Note the two changes:
* The resulting SAM type changed from `Condition<String!>` to
  `Condition<Any?>`. This is exactly the point of the "careful
  approximation" change, because just erasing the "in" projection from
  the parameter type is incorrect, see the explanation for that change.
* The value is now implicitly cast to the _non-null_ function type
  before it is SAM-converted. The presence of the cast is fine, but the
  fact that it's to a non-null type is an oversight.

The target type for this cast is computed at
`KotlinType.getSubstitutedFunctionTypeForSamType` in psi2ir. Now it
extracts the nullability from the SAM type and retains it in the
resulting function type.

After this change, the IR for the argument becomes:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>!
      GET_VAR filter type=Function1<String, Boolean>?

Note that the target type is now flexible, as the resulting SAM type.
Another option would be to make it nullable, as the type of the
functional value, but there doesn't seem to be any difference.

 #KT-54600 Fixed
2022-10-25 11:20:23 +00:00
Mikhail Glukhikh c0789b5207 PSI/FIR->IR translators: return to 1.7.10 behavior for field references
In 1.7.20 we used the nearest Java-based receiver for such field
references in backend. Now we are using use-site receiver again,
it can lead to accidental usage of derived class property backing field.

This is effectively a revert of KT-49507 fix, see commits:
- fa914f20
- b0a6508d

#KT-54393 Fixed
#KT-49507 Planned
#KT-52338 Planned
2022-10-25 08:36:01 +00:00
Jinseong Jeon 14213ddad2 AA: fix expected type for lambda with explicit label 2022-10-24 22:07:05 +02:00
Vsevolod Tolstopyatov b29309478e Take into account 'KTypeImpl.classifier' in its hashCode and equals
Since KT-53308, we started to cache results of typeOf invocation
in reflection. The cache uses the origin 'KClassifier' as a key with
an optional list of 'KTypeProjection' in type argument position,
and computed result as a value.

Without classifier check, the caching produces incorrect execution in
a very specific classloaders usage which is leveraged
by IDEA source-tree:

* All Kotlin stdlib and reflect classes are always loaded by the same
  classloader
* Other classes that depend on Kotlin are loaded by separate
  classloaders

The reproducer:

* Attempt to use typeOf<kotlin.List<Foo>> from one classloader caches
  the resulting KType
* Attempt to use typeOf<kotlin.List<Foo>> from another classloader
  for the same 'Foo' that differs only in classloader reuses the
  computed KType, meaning that KType type argument classifier
  is simply incorrect and points to the 'Foo' from the first classloader

#KT-54611 Fixed
#KT-54629 Fixed

Merge-request: KT-MR-7470
Merged-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>
2022-10-24 19:05:08 +00:00
Pavel Punegov c098ba789c [K/N][perf] JS IR Gradle DSL syntax changed to JS
Merge-request: KOTLIN-MR-532
Merged-by: Pavel Punegov <pavel.punegov@jetbrains.com>
2022-10-24 17:58:18 +00:00
Sebastian Sellmair fb5ae330fc [Gradle][MPP] KotlinTargetHierarchyDsl: Add test for custom hierarchy
^KT-53570 Verification Pending
2022-10-24 14:34:50 +00:00
sebastian.sellmair fef1de8620 [Gradle][MPP] KotlinTargetHierarchyBuilderImpl: Support KotlinWithJavaTarget
^KT-53570 Verification Pending
2022-10-24 14:34:49 +00:00
sebastian.sellmair c332c928fc [Gradle][MPP] Refine naming for KotlinTargetHierarchyBuilder
^KT-53570 Verification Pending
2022-10-24 14:34:49 +00:00
sebastian.sellmair 1a519a8159 [Gradle][MPP] Add test cases for KotlinTargetHierarchy*
^KT-53570 Verification Pending
2022-10-24 14:34:49 +00:00
Sebastian Sellmair da8a18920d [Gradle][MPP] Mark KotlinTargetsContainer and KotlinTargetHierarchyBuilder with KotlinTargetsDsl annotation
To prevent confusing shortcuts defined on `KotlinTargetsContainer`
when declaring a KotlinTargetHierarchy:

e.g.

```kotlin
kotlin {
    targetHierarchy.default {
        common {
            ios() // <- [DSL_SCOPE_VIOLATION]
            //'fun ios(): Unit' can't be called in this context
            // by implicit receiver. Use the explicit one if necessary
        }
    }
 }
```

^KT-53570 Verification Pending
2022-10-24 14:34:48 +00:00
Sebastian Sellmair 0c114b9664 [Gradle][MPP] CommonizerHierarchicalIT: Use targetHierarchy API
^KT-53570 Verification Pending
2022-10-24 14:34:48 +00:00
Sebastian Sellmair e84dac45d7 [Gradle][MPP] Update kotlin-gradle-plugin-api api reference
^KT-53570 Verification Pending
2022-10-24 14:34:48 +00:00
Sebastian Sellmair 1823e0fad4 [Gradle][MPP] KotlinTargetHierarchyBuilderImpl: only build child groups if explicitly included
^KT-53570 Verification Pending
2022-10-24 14:34:47 +00:00
Sebastian Sellmair 487368d9df [Gradle][MPP] KotlinTargetHierarchyDescriptor: Remove function supertype
^KT-53570 Verification Pending
2022-10-24 14:34:47 +00:00
Sebastian Sellmair a8a861e1ce [Gradle][MPP] KotlinTargetHierarchyBuilder: implement w/ include & exclude predicates
^KT-53570 Verification Pending
2022-10-24 14:34:47 +00:00
Sebastian Sellmair c5d6162578 [Gradle][MPP] Implement initial KotlinTargetHierarchy APIs
^KT-53570 Verification Pending
2022-10-24 14:34:46 +00:00
Ivan Kylchik 1fc2575052 Use correct toString method in IrCompileTimeChecker for analysis 2022-10-24 13:14:16 +00:00
Ivan Kylchik 5b16b2c71e Properly verify args in string concatenation expression for interpreter
If string concatenation contains object value, then this argument
will not have explicit toString call. We must find and check toString
method manually.

#KT-54615
2022-10-24 13:14:16 +00:00
Alexander Udalov c813e03c1e Kapt+JVM_IR: do not generate nested enum as final
#KT-54187 Fixed
2022-10-24 12:48:22 +00:00
Dmitriy Novozhilov 766a51069c Advance bootstrap to 1.8.20-dev-1438 2022-10-24 12:24:40 +00:00
Alexander Korepanov 39666dafa5 [JS IR] Make JS IR IC info messages more pretty and usable 2022-10-24 12:05:05 +00:00
Anton Lakotka f5d9819c3f [Gradle] Update watchosDeviceArm64 target preset
^KT-54583 Verification Pending
2022-10-24 11:20:52 +00:00
Anton Lakotka fe2ee9886d [Gradle] watchosDeviceArm64 should not run simulator tests
This reverts commit 640ba1ec

^KT-54583 Verification Pending
2022-10-24 11:20:51 +00:00
Pavel Punegov 259d58c817 [K/N] Rename jsIr preset usage back to js
Merge-request: KT-MR-7467
Merged-by: Pavel Punegov <Pavel.Punegov@jetbrains.com>
2022-10-24 10:44:23 +00:00
Artem Kobzar 14e4febb05 [K/JS] Exclude default from the regular reserved keywords to give ability to export declarations with default export ^KT-54480 Fixed
fix(KT-54480): exclude default from the regular reserved keywords to give ability to export intities with default export.

Merge-request: KT-MR-7459
Merged-by: Artem Kobzar <Artem.Kobzar@jetbrains.com>
2022-10-24 10:12:30 +00:00
Yahor Berdnikau 57578b569e Substitute stdlib-jdk7{,8} dependencies with stdlib
Only when dependencies contain kotlin-stdlib-1.8+ dependency. Such
substitution could be disabled via 'gradle.properties' by adding 'kotlin
.stdlib.jdk.variants.substitution=false'.

^KT-54136 Fixed
2022-10-24 09:21:22 +00:00
pyos 65c153a722 JVM: consider casts of null to be redundant
These should only have ever been necessary for field type inference in
coroutines, which should have been fixed by 0fc676a20c.

Unlike 903a5d69a4, this time the change is in an optimization pass.
Advantage: optimization passes have a closer to the JVM view of the
bytecode, which makes this change significantly more likely to be correct.
Disadvantage: technically we don't really guarantee optimization passes
other than FixStack will run at all. For KT-54581 this is 100% fine
since the problem itself is caused by redundant checkcast elimination in
the first place (otherwise there would've been a redundant cast to
String), but for KT-53146 this means the fix is somewhat incidental and
not necessarily guaranteed.

^KT-53146 Fixed
^KT-54581 Fixed
2022-10-24 11:11:21 +02:00
vladislav.grechko 6f4a60ac91 Fix equality comparison for inline class over inline class
^KT-54536: Fixed
2022-10-21 21:17:40 +00:00
vladislav.grechko db133bedf9 Fix ClassCastException on equality comparison on inline class objects
^KT-54603: Fixed
2022-10-21 21:17:40 +00:00
Ilya Goncharov 2abceb1ca5 [Gradle, JS] Enable test when fixed problems with klib
This reverts commit 03bea0dbaa.
2022-10-21 14:56:26 +00:00
Alexander Udalov 8812f632cc Fix optimization of property delegates of platform types
The old code didn't replace the delegate field access because it was
wrapped into a TYPE_OP IMPLICIT_NOTNULL.

 #KT-54463 Fixed
2022-10-21 13:23:38 +00:00
vladislav.grechko ac74ce5f27 Minor: check absence of context receiver parameters 2022-10-21 12:57:12 +00:00
vladislav.grechko c990bbb26c Get rid of excess method in compiled inline class with custom equals
^KT-54501: Fixed
2022-10-21 12:57:11 +00:00
vladislav.grechko 70c2f2b86f Support specifying different bytecode listings for FIR and old frontend 2022-10-21 12:57:11 +00:00
Artem Kobzar 8a89b2f29f [K/JS] Remove the old interface runtime check because of bootstrapping
Merge-request: KT-MR-7457
Merged-by: Artem Kobzar <Artem.Kobzar@jetbrains.com>
2022-10-21 11:34:31 +00:00
Pavel Punegov ae7404878f [K/N][test] Add test on jar contents.
* Check jar for included entries.
* Small changes to embeddable jar smoke test.
* Delete not used test.
2022-10-21 10:33:41 +00:00
Pavel Punegov d2c58cdd27 [K/N][build] Dependencies fixes: trove4j and kotlin-compiler
* Depend on kotlin-compiler project instead of its runtimeElements only
* trove4j fixes: add as a dependency and use common version
* Strip dependencies in different projects: remove unnecessary
2022-10-21 10:33:40 +00:00
Artem Kobzar ea6b784e41 [K/JS] Exclude Enum.entries property from export to JS 2022-10-21 10:31:06 +00:00
Martin Petrov 6c0b4bcfd4 [KT-54284][Native] Produce deterministic klibs from cinterop. (#4979)
Pass in temp-file C sources to clang via stdin instead of by name.
This prevents absolute paths of temp files from being encoded in bitcode.
2022-10-21 12:16:34 +02:00
Amit Sharma 68bcff3194 Use default build-tool version in test projects 2022-10-21 09:12:46 +00:00
Ilya Chernikov 8566589cf5 Add minimal roots deduplication on classpath update
duplication was detected e.g. in some scripting scenarios
2022-10-21 06:11:42 +00:00
Ilya Chernikov b50a803b6f Make jdk root processing more robust
#KT-54337 fixed
2022-10-21 06:11:42 +00:00
Ilya Chernikov 942def5828 Preserve app env in FP tests to benefit from FastJarFS caching 2022-10-21 06:11:42 +00:00
Ilya Chernikov 7d5257c258 Preserve FastJarFS in app env and implement intermediate cleanup
FastJarFS was behaving differently than the regular CoreJarFS it
tries to replace, namely it was cleaned after each compilation
(had the lifetime tied to core env).
This commit preserve it in the app env the same way as CoreJarFS,
so it could be reused in parallel builds and preserved if automatic
cleanup of the app env is turned off,
But since FastJarFS caches also mmf handles, the additional handles
cleaning is introduced that triggers after all possibly parallel
compilations are finished.
2022-10-21 06:11:41 +00:00
Ilya Chernikov 61e9aaf113 Convert java to kotlin 2022-10-21 06:11:41 +00:00
Ilya Chernikov bccfc2ad18 Rename .java to .kt 2022-10-21 06:11:40 +00:00
Ilya Goncharov 91f75a9187 [Gradle, JS] Both mode will leave as it was with legacy base
Because of both mode will be removed too (because it is redundant when legacy is deprecated), so it is no sense to change it
2022-10-20 20:23:49 +00:00
Ilya Muradyan 352af4b245 Make the code compatible with IDE plugin 2022-10-20 16:00:42 +02:00