Commit Graph

5820 Commits

Author SHA1 Message Date
Alexander.Likhachev a19bd2ed2e [Build] Migrate most of the build logic from Project.buildDir usage
It's going to be deprecated in Gradle 8.3

There's currently no way to pass a `org.gradle.api.provider.Provider` to the JavaExec.systemProperty or Test.systemProperty. There's a workaround using `org.gradle.process.CommandLineArgumentProvider`, but I intentionally don't rework these calls as Gradle is going to allow passing providers to configure system properties: https://github.com/gradle/gradle/issues/12247#issuecomment-1568427242
^KTI-1473 In Progress
2023-12-07 18:31:06 +00:00
Mikhail Glukhikh 06ce57ea56 K2: report MISSING_DEPENDENCY_CLASS for lambda parameters if needed
#KT-62525 Fixed
2023-12-05 18:16:52 +00:00
Leonid Startsev 36703ff9ae Implement strict and lenient modes for Kotlin metadata reading
In strict mode, an exception will be thrown when inconsistent metadata is encountered. In lenient mode, the reader will attempt to handle the inconsistent metadata by ignoring certain inconsistencies. This is a solution to a problem of reading metadata 'from the future' that is not allowed by default, but desired in certain cases. See updated ReadMe for details.

Also fix problem with Strict Semantics flag.

#KT-57922 Fixed
#KT-59441 Fixed
2023-12-01 17:43:11 +00:00
Kirill Rakhman 560c1cacf3 [FIR] Fix capturing of flexible types during resolution
Previously, because we didn't handle flexible types properly in
prepareCapturedType, projections inside flexible types would only be
captured during subtyping with captureStatus=FOR_SUBTYPING
which would lead to the constraint type being wrongly approximated
(see ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint).

Fixing the capturing produced two kinds of false positive diagnostics:

1. In ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint we would get two instances of cone types
that are structurally equal and containing the same captured type.
However, because we only skipped subtyping if the types were
referentially equal, we would get a contradiction here.
The fix was to use structural equality instead, which should be okay
as the captured type instances are the same.

2. Reified type variables were inferred to captured types because
flexible arrays with captured upper bounds
(Array<Foo>..Array<Captured(out Foo)>?) were not properly approximated.

#KT-62609 Fixed
2023-11-30 08:54:26 +00:00
Evgeniy.Zhelenskiy 5258e2044d [FIR] Forbid annotations on anonymous initializers and destructuring declarations
#KT-59896


Merge-request: KT-MR-13197
Merged-by: Evgeniy Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>
2023-11-28 11:59:26 +00:00
Svyatoslav Kuzmich 6b6353f3b9 [Wasm] Add external file checker to K2
#KT-56849
2023-11-27 16:55:04 +00:00
Nikita Bobko 7166adb179 [FIR, IR] Convert FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker into ExpectActualCheckingCompatibility
FirDefaultArgumentsInExpectActualizedByFakeOverrideChecker is an adhoc
checker which can be converted to ExpectActualCheckingCompatibility to
reuse common expect-actual checking infrastructure.

^KT-62913 Fixed
Review: https://jetbrains.team/p/kt/reviews/13094/timeline

Tests that were broken by one of my previous commits are now fixed:
- actualFakeOverride_paramsAreCompatibleViaSharedMethodWithDefaultParams.kt
- inheritedJavaMembers.kt

DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE diagnostic
disappeared in delegation.fir.kt because only one
AbstractExpectActualChecker incompatibility can be reported at a time
(DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE is now reported
not by adhoc checker but by common AbstractExpectActualChecker). It
would be nice to report both of them, but it's a separate issue KT-62631

delegation2 test makes sure that
DEFAULT_ARGUMENTS_IN_EXPECT_ACTUALIZED_BY_FAKE_OVERRIDE is reported when
NO_ACTUAL_CLASS_MEMBER_FOR_EXPECTED_CLASS is fixed
2023-11-24 18:02:49 +00:00
Ivan Kochurkin 115d685d91 [FIR] Fix ambiguity of Throws and other std annotations importing
Including `SharedImmutable` and `ThreadLocal`

Simplify code, remove `DefaultImportPriority.KOTLIN_THROWS`

Introduce `FirNativeClassMapper`
2023-11-23 23:51:23 +00:00
Svyatoslav Kuzmich b3bc99a44a [Build] Use impl dependencies for compiler.common.{web,wasm}
Refactor build scripts to use implementation dependencies instead of api
for finer grained recompilations.
2023-11-23 15:52:55 +00:00
Svyatoslav Kuzmich d219d5380b [Wasm] Move FirJsQualifierChecker to web.common and reuse in Wasm
#KT-56849
2023-11-23 10:42:56 +00:00
Svyatoslav Kuzmich c1fa0a3e8c [Web] Move common ids from WasmStandardClassIds to WebCommonStandardClassIds 2023-11-23 10:42:56 +00:00
Svyatoslav Kuzmich 910835af2d [Web] Add core/compiler.common.web module
Add WebCommonStandardClassIds object to use in JS&Wasm shared code
2023-11-23 10:42:56 +00:00
Ilya Gorbunov d8ee74222f [builtins-gen] Explicit visibility for companion objects and secondary constructors 2023-11-22 18:04:34 +00:00
Ilya Gorbunov ab7c2f2196 [stdlib] Explicit visibility and return types: builtins 2023-11-22 18:04:34 +00:00
Svyatoslav Kuzmich 31560217f8 [Wasm] Port @JsFun checker to K2 (KT-56849)
^KT-62724 Fixed
2023-11-20 14:39:24 +00:00
Mikhail Glukhikh 0aa5170ba2 K2: delay jspecify strict mode introduction to version 2.1
Related to KT-62352, KT-55586
2023-11-17 08:21:04 +00:00
Ivan Kochurkin 0efcad51e9 [FIR] Add a comment to isSubtypeOfClass that explains what this method does
And what the difference is between `isSubtypeOf` and `isSubtypeOf`
2023-11-16 19:29:58 +00:00
Mikhail Glukhikh 1eacd5efc2 K1/K2: support org.jspecify.annotations.NonNull in Java interop
#KT-62352 Fixed
2023-11-16 11:13:44 +00:00
Ilya Gorbunov 26183237ab Make :core:builtins:serialize more remote build cache friendly
On CI when populating build cache, the build runs
with --info logging level causing an additional jvm argument
provided to the task.
This argument is usually not provided in local builds.
The argument only affects task printout and not its outputs.
2023-11-15 10:32:09 +00:00
Svyatoslav Kuzmich 1c230c8f27 [Wasm] Port WasmImport/WasmExport checker to K2 (KT-56849) 2023-11-14 12:24:10 +00:00
Nikita Bobko dfe048a96a [FIR] Cleanup: drop unused ExpectActualMemberDiff
- It became unused after cc70f78027
- And it's not going to become used in the nearest future, since in K2,
  we won't have "member scopes" check on frontend (for now)
2023-11-07 15:11:49 +00:00
Egor Kulikov 408e2f109f [FIR] Correctly process slash in class name in ClassId
^KTIJ-27358 fixed


Merge-request: KT-MR-12673
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2023-11-07 09:47:05 +00:00
Nikita Bobko 8722e142f6 [IR] 2/2 Propogate expect-actual checker incompatibilities to IR backend
Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:20 +00:00
Nikita Bobko eb0c8c00c3 [FIR, IR] 1/2 Minimize usages of ExpectActualCompatibility, MismatchOrIncompatible and MatchedOrCompatible
- Migrate ExpectActualCompatibility -> ExpectActualCheckingCompatibility
  where the "checker" is expect
- Migrate ExpectActualCompatibility -> ExpectActualMatchingCompatibility
  where the "matching" is expect

KT-62590 in progress. A lot of tests start to fail now. I will fix them
in next commits

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko 664b9cc3ba [FIR, IR] ClassScopes incompatibility: split unfulfilled incompatibilities into "mismatchedMembers" and "incompatibleMembers"
KT-62590 is in progress

Unfortunatelly, ACTUAL_ANNOTATIONS_NOT_MATCH_EXPECT is now reported
twice in 'classScopeViaTypealiasIncompatible' test.

We had a duplicated diagnostic in other cases before my commits, anyway.
it will be fixed in
https://youtrack.jetbrains.com/issue/KT-62559/KMP-K2-prevent-reporting-ACTUALANNOTATIONSNOTMATCHEXPECT-twice-in-CLI#focus=Comments-27-8293687.0-0

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:19 +00:00
Nikita Bobko d0b34fe378 [FIR, IR] Refactor: restructure ExpectActualCompatibility class hierarchy
KT-62590 is in progress

This commit is pure refactoring.
- No tests changed their behaviour
- Semantics isn't changed

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:18 +00:00
Nikita Bobko a3401b2f9e Minor: cleanup + support variance in ErrorListDiagnosticListRenderer
1. Support variance in ErrorListDiagnosticListRenderer.
   I will make some diagnostics to have covariant type arguments in the
   next commits
2. Drop unused code

Review: https://jetbrains.team/p/kt/reviews/12750/timeline
2023-11-06 14:41:17 +00:00
Nikita Bobko bc5180656d [FIR] ReturnType expect-actual incompatibility: convert from strong to weak
It should have been WeakIncompatible from the beginning because it's not
possible to overload by return type in Kotlin

This commit is a step forward to fix KT-62591

Unfortunately, the test cannot demonstrate the problem because of
another bug in K2 KT-59887

^KT-62752 Fixed
Review: https://jetbrains.team/p/kt/reviews/12750/timeline

Motivation:

It makes expect-actual matching-checking model more consistent.

expect-actual "matching" is run before FirResolvePhase.BODY_RESOLVE. You
can't know return types, until you run BODY_RESOLVE. That's why the
return type can't be checked during expect-actual matching. But it's
cursed: you have something that have to match by, but, at the same time,
you can't do it.

expect-actual "checking" is run after FirResolvePhase.BODY_RESOLVE.
That's why if we convert ReturnType incompatibility to WeakIncompatible
(which should have been called CheckingIncompatible), then expect-actual
matching model becomes consistent.

We will also be able to get rid of unnecessary
FirActualCallableDeclarationChecker. Because it won't be necessary.
Return types will be checked by common logic of expect-actual "checker"
2023-11-06 14:41:16 +00:00
Sergej Jaskiewicz c5f519f7c7 [FIR/IR generator] Commonize visitor printing logic
This is a step towards commonizing the code generator between
FIR and IR: KT-61970

Also, don't use kotlinpoet for generating IR visitors (KT-61703)
2023-11-02 23:05:18 +00:00
Pavel Kirpichenkov 2d10877fda [refactoring] extract base class for annotation loaders
Annotation loaders for descriptors (AnnotationAndConstantLoaderImpl) and
stubs (AnnotationLoaderForStubBuilderImpl) share the loading logic until
mapping ProtoBuf.Annotations to output values. The shared logic has been
extracted to the base class.

KTIJ-26761
KTIJ-26961
2023-11-02 10:28:37 +00:00
Kirill Rakhman ac203591e5 [FE, Java resolve] Support inheritors of sealed Java type without permits clause
This fixes a false negative NO_ELSE_IN_WHEN in K2 and incidentally
also fixes a false positive NO_ELSE_IN_WHEN in K1 since the fix is in
the common code.

#KT-62491 Fixed
2023-10-31 13:41:56 +00:00
Svyatoslav Kuzmich 15d3bf5e25 [Wasm] Port JS interop type checker to K2 (KT-56849) 2023-10-31 12:34:32 +00:00
Alexander Korepanov 71eaf651e8 [JS FIR] Implement JSCODE_ARGUMENT_NON_CONST_EXPRESSION FIR checker
The meaning of this check is the same as K1
JSCODE_ARGUMENT_SHOULD_BE_CONSTANT and JSCODE_ARGUMENT_NON_CONST_EXPRESSION
diagnostics.

The main difference is that K2 JSCODE_ARGUMENT_NON_CONST_EXPRESSION
diagnostic checks the js() argument in the same way as
const val initializers or annotation arguments are checked.

This means that, the K2 diagnostic is stricter than original
K1 JSCODE_ARGUMENT_SHOULD_BE_CONSTANT diagnostic,
which allows the use of non-constant vals.

^KT-59435 Fixed
2023-10-26 19:22:14 +00:00
Sergej Jaskiewicz aaf7ccbebd [util] Introduce IndentingPrinter interface
This interface is more convenient to pass around so that it's easier
to replace different printer implementations.
2023-10-25 13:04:15 +00:00
Sergej Jaskiewicz 895d107ac5 [util] Convert Printer from Java to Kotlin 2023-10-25 13:04:14 +00:00
Sergej Jaskiewicz c442d0e159 [util] Rename Printer.java to Printer.kt before converting it to Kotlin
This is to preserve the Git history of the file.
2023-10-25 13:04:14 +00:00
Ivan Kochurkin 1827df82c4 Removed useless as casts from compiler code
It allows compiling code with K2 and enabled `-Werror`
2023-10-24 20:59:56 +00:00
Nikita Bobko fa89b8b0f1 [FE 1.0] 2/2 Don't report a warning when new members are added to open expect actualization
^KT-62655 Fixed
2023-10-20 14:37:10 +00:00
Nikita Bobko a537ab898e [FE 1.0] Refactoring: replace defensive NonPrivateCallableAdded with Unknown
Motivation: I'm going to drop NonPrivateCallableAdded (KT-62655) in the
next commits. But I don't want to change the existing logic when I drop
it. That's why I have to introduce the "Unknown" case
2023-10-20 14:37:10 +00:00
Nikita Bobko 12f932a63a [FE 1.0] Report a more precise diagnostic when parameter modifiers (vararg) are changed in actualization
^KT-62747 Fixed
2023-10-20 14:37:10 +00:00
Alexander Udalov 931c2ce47a Reflection: fix calling suspend fun returning value class over primitive
#KT-47973 Fixed
2023-10-20 08:50:26 +00:00
Evgeniy.Zhelenskiy b89d8a65a1 [Reflection] Fix parsing JVM function descriptors
#KT-60708
2023-10-19 19:09:31 +00:00
Dmitriy Novozhilov 704e2ef5c5 Suppress K2 specific warnings in the codebase
^KT-62472
2023-10-18 07:59:27 +00:00
Alexander Udalov c33c918bd4 IR: add IrClass.hasEnumEntries
This flag will be used on JVM to determine whether or not to generate
external enum entries mappings ("$EntriesMappings") classes. Note that
from the frontend's point of view, every enum has `entries`, so for
backend purposes we have to reach out to the underlying deserialized
data to read the flag from the metadata.
2023-10-16 20:22:20 +00:00
Roman Golyshev 648330da50 [kotlin] Make SmartSet implement MutableSet for more type-safety
`AbstractSet` is a java class, and it brings flexible types with it.
Because of it, it was possible to write the following code:

```kt
fun usage() {
  val mySet = SmartSet.create<String>() // should not contain nulls
  mySet += null // compiles because of flexible types
}
```

Using `AbstractMutableSet`
as a base class does not change the implementation,
but explicitly adds a proper kotlin `MutableSet`
interface to the class, making it more type-safe
2023-10-16 16:25:17 +00:00
Roman Efremov 423f4ca5f0 [FE, IR] Check compatibility of annotations set on type usages in expect and actual declarations
This includes checking of annotatins set on:

- value parameter types
- type parameter bound types
- extension functions receiver types
- function return types
- class super types

Fix in `defaultParams_inheritanceByDelegation_positive.kt`
is needed because of problem in resolution of implicit return types
(KT-62064), which leads to crash in annotation checker, because it
expects resolved return type.

MR: KT-MR-12245

^KT-60671 Fixed
2023-10-16 10:48:08 +00:00
Svyatoslav Kuzmich 1ddcdb95bd [Wasm] Add compiler.common.wasm module
This module is introduced to mirror K/JS code layout
Add WasmStandardClassIds to use in checkers
2023-10-12 13:26:58 +00:00
Ilya Kirillov 86c8f3cc35 Remove obsolete @OptIn(ExperimentalUnsignedTypes::class) annotations
^KT-62510
2023-10-12 10:41:00 +00:00
Ilya Kirillov f11cb277cd Remove obsolete @OptIn(ExperimentalStdlibApi::class) annotations
They were added when `buildList`, `buildMap` and `buildSet` were experimental.

^KT-62510
2023-10-12 10:41:00 +00:00
Anastasia.Nekrasova e3bab4a7da [K2] Prohibit smart casts for 'expect' properties
^KT-61340
2023-10-11 17:05:29 +00:00