Commit Graph

272 Commits

Author SHA1 Message Date
Svyatoslav Kuzmich 54a45c49f8 [Wasm] Add Wasm platform and K1 FE infrastructure 2023-02-24 01:05:23 +01:00
Dmitriy Novozhilov bdf8e6f3a5 [FIR] Extend capacity of ArrayMapImpl until it fits required size
There are cases when we have some indices in TypeRegistry left from
  previous compilations, so registering new service may increase index
  not by one
So such situation is possible:
First compilation (jvm project): register 20 different jvm services in
  session + one from compiler plugin (with index 21)
Second compilation (common project): register only 10 common services in
  session + one from compiler plugin (with index 21)
*numbers are imaginary

And in this situation increasing `ArrayMapImpl.data` size only one time
  may not cover required index

^KT-56685 Fixed
2023-02-16 10:25:20 +00:00
Dmitriy Novozhilov 89c42e20c9 [FIR] Consistently use _function_ instead of _functional_ in names of classes and functions 2023-02-02 08:24:52 +00:00
Dmitriy Novozhilov d1b797ed97 [FIR] Generify resolution and inference of arguments of functional types 2023-02-02 08:24:50 +00:00
Dmitriy Novozhilov 67aa80562d [FE] Completely replace FunctionClassKind with FunctionalTypeKind
FunctionalTypeKind can be used in FE 1.0 too, so there is no need to
  keep both classes. Also, removal of FunctionClassKind simplifies work
  with FunctionalTypeKind in common code, like Analysis Api
2023-02-02 08:24:50 +00:00
Dmitriy Novozhilov e0c8f2354a [FIR] Properly implement FirFunctionalTypeKindService
This implementation takes additional functional type kinds from compiler
  plugins into account
2023-02-02 08:24:49 +00:00
Nikolay Lunyak e2403c801f [FIR] KT-55747: Report error for operator fun mod
^KT-55747 Fixed

Merge-request: KT-MR-8522
Merged-by: Nikolay Lunyak <Nikolay.Lunyak@jetbrains.com>
2023-01-30 08:48:33 +00:00
Ivan Kochurkin e22359cc10 [FIR] Add MetadataSymbolProvider
Extract common code from K1 to MetadataUtil
2023-01-24 15:27:12 +00:00
Denis.Zharkov dab50daf56 K2: Add ability identify DI components by string key instead of KClass
It allows having several the same typed-component in the container
2023-01-19 10:57:42 +00:00
Mikhail Glukhikh cbedbda527 Enhance API/messages around BinaryVersion / JvmMetadataVersion 2023-01-16 18:16:07 +01:00
Dmitriy Novozhilov d5a76a1b3b [AA LC] Keep original qualifier while translating error cone types to Psi types 2023-01-12 17:45:08 +00:00
Dmitriy Novozhilov bd26c29229 [FIR] Resolve arguments of error types during type resolution 2023-01-12 17:45:06 +00:00
Nikolay Lunyak 227969d787 [FIR JS] Support DYNAMIC_RECEIVER_NOT_ALLOWED 2023-01-09 08:57:10 +00:00
Nikolay Lunyak 95b589fd94 [FIR JS] Support DEBUG_INFO_DYNAMIC 2023-01-09 08:57:09 +00:00
Nikolay Lunyak eed2fada1f [FIR JS] Support WRONG_MULTIPLE_INHERITANCE 2023-01-09 08:57:09 +00:00
Dmitrii Gridin 6cea761b6e [SLC] reduce resolve from ANNOTATIONS_ARGUMENTS_MAPPING to TYPES phase on annotations search 2023-01-06 21:09:41 +00:00
Kirill Rakhman 2a724787f0 K2: fix SUPERTYPE_NOT_INITIALIZED not being reported on object expressions ^KT-55597 Fixed 2023-01-04 15:09:26 +00:00
Kirill Rakhman 721a37f7e7 K2: implement FirLateinitIntrinsicApplicabilityChecker ^KT-55495 Fixed 2023-01-04 14:42:43 +00:00
Pavel Mikhailovskii fed86a57e3 Fix isValidJavaFqName 2023-01-04 11:28:08 +00:00
Alexander Udalov ae6d4d268d Use short copyright from COPYRIGHT_HEADER in generated files 2023-01-02 22:52:18 +01:00
Dmitriy Novozhilov c44993e586 [FE] Use FQN instead of KClass in TypeRegistry
TypeRegistry is the static map which contains mapping between type of
  session component and its index in the session array. Originally
  `KClass` of a component was used as a key in this map, which worked
  pretty well for compiler components. But there was a problem with
  components from plugins and Kotlin daemon: in compilation with daemon
  we keep TypeRegistry between compilations. But for each compilation
  we load plugins from jar, which brings to the situation when after N
  compilations there is N entries in TypeRegistry map with different
  KClass'es for same extension component. This not only causes AIOBE
  but also introduces the memory leak, because we keep reference to
  KClass which is not used anymore

So to fix this issue it's enough to just store FQN of component in
  TypeRegistry instead of KClass

There are no tests in this commit, but they will be added in next
  commit relevant to scripting. With those commits we will have gradle
  integration tests which uses Kotlin compiler daemon and registers
  a compiler plugin for scripting

^KT-55023 Fixed
2022-12-21 10:33:03 +00:00
Dmitriy Novozhilov 890418f6b7 [FE] Add detailed report to possible failures in ComponentArrayOwner.registerComponent 2022-12-21 10:33:02 +00:00
Dmitrii Gridin f3c7972d20 [SLC] implement java annotations for annotation classes
^KT-55481 Fixed
2022-12-20 19:52:10 +00:00
Mikhail Glukhikh 8580461b5b FIR2IR: remove redundant calls of preCacheBuiltinClassMembers
#KT-55421 Fixed
2022-12-16 11:37:02 +00:00
Mikhail Glukhikh 26ff806440 EmptyIntersectionTypeChecker: don't take stub & error types into account
This commit fixes some tests broken by previous refactorings
2022-12-09 15:00:42 +00:00
Mikhail Glukhikh a7840d10d4 Drop unused AbstractTypeChecker.areRelatedBySubtyping 2022-12-09 15:00:42 +00:00
Mikhail Glukhikh 56c818e0a9 EmptyIntersectionTypeChecker: drop redundant checks + extra cleanup 2022-12-09 15:00:41 +00:00
Mikhail Glukhikh 758a4931e3 EmptyIntersectionTypeChecker: drop also incompatible supertypes check
Incompatible supertypes check also don't provoke runtime problems
in most situations, because this check is also bound to type argument
conflict. Related to KT-54411
2022-12-09 15:00:41 +00:00
Mikhail Glukhikh 29ad5f981c Extract EmptyIntersectionTypeKind.isDefinitelyEmpty to a property 2022-12-09 15:00:41 +00:00
Mikhail Glukhikh 4d01ad439a EmptyIntersectionTypeChecker: simplify code 2022-12-09 15:00:40 +00:00
Mikhail Glukhikh 2a1a5c6936 EmptyIntersectionTypeChecker: drop questionable check of arguments
The situations with conflicting type arguments normally don't provoke
any runtime problems. Also, conflicts like A<T> VS A<SomeType> aren't
valid at all. Here we decided to remove them to avoid strange
and non-actionable warnings in user code.

#KT-54411 Fixed
2022-12-09 15:00:40 +00:00
Mikhail Glukhikh 832baf81e5 EmptyIntersectionTypeChecker: fix error in diagnostic text
Related to KT-54411
2022-12-09 15:00:39 +00:00
Mikhail Glukhikh 7fed0c64f0 EmptyIntersectionTypeChecker: minor refactoring 2022-12-09 15:00:39 +00:00
Mikhail Glukhikh caf511acc5 EmptyIntersectionTypeChecker: make some names more clear 2022-12-09 15:00:38 +00:00
Mikhail Glukhikh e9ea66b9f1 EmptyIntersectionTypeChecker: fix typo in variable name 2022-12-09 15:00:38 +00:00
pyos a9be27e330 FIR CFG: add union nodes
Quick quiz:

 Q: In a CFG, what does `a -> b -> c -> d` mean?
 A: `a`, then `b`, then `c`, then `d`.

 Q: In a CFG, what does `a -> b -> d; a -> c -> d` mean?
 A: `a`, then `b` or `c`, then `d`.

 Q: So how do you encode "a, then (b, then c) or (c, then b), then d`?
 A: You can't.

Problem is, you need to, because that's what `a; run2({ b }, { c }); d`
does when `run2` has a contract that it calls both its lambda arguments
in-place: `shuffle(listOf(block1, block2)).forEach { it() }` is a
perfectly valid implementation for it, as little sense as that makes.

So that's what union nodes solve. When a node implements
`UnionNodeMarker`, its inputs are interpreted as "all visited in some
order" instead of the normal "one of the inputs is visited".

Currently this is used for data flow. It *should* also be used for
control flow, but it isn't. But it should be. But that's not so easy.

BTW, `try` exit is NOT a union node; although lambdas in one branch can
be completed according to types' of lambdas in another, data does not
flow between the branches anyway (since we don't know how much of the
`try` executed before jumping into `catch`, and `catch`es are mutually
exclusive) so a `try` expression is more like `when` than a function
call with called-in-place-exactly-once arguments. The fact that
`exitTryExpression` used `processUnionOfArguments` in a weird way
should've hinted at that, but now we know for certain.
2022-12-08 10:19:29 +00:00
Marco Pennekamp 2cd16f055a [AA] KT-55098 Render context receivers in declarations & function types
- `context(...)` is a modifier that must precede annotations and other
  modifiers, so for declarations it is rendered in
  `renderAnnotationsAndModifiers`.
- Ignore `@ContextFunctionTypeParams` in the annotation list of FE10
  types, as the annotation is an implementation detail of context
  receivers in K1 and shouldn't be rendered.

^KT-55098 fixed
2022-12-06 17:43:30 +00:00
Steven Schäfer 21fef70367 Standardize context receiver parameter names
Previously, FIR used `_context_receiver_n` while FE10 used `<this>` for
all context receiver parameters. This commit changes the code in FE10
to follow the convention from FIR.
2022-12-03 00:11:38 +01:00
Mikhail Glukhikh 5cf1a88c42 FE: move delegate name functions to NameUtils 2022-12-02 21:54:18 +00:00
Steven Schäfer a7ba081d22 FIR: Fix interface delegation ABI
- Unifies the name of the `$$delegate_<n>` field between K1 and K2.
- Make the `$$delegate_<n>` field private
2022-12-02 21:54:18 +00:00
Dmitriy Novozhilov ac7fddaad5 [FE] Always infer upper types to intersection types in K2...
...and always use old algorithm for K1

^KT-51221
2022-11-29 12:25:44 +00:00
Dmitriy Novozhilov 1b27d60307 [FIR] Support @OnlyInputTypes annotation
^KT-54807 Fixed
2022-11-22 15:46:17 +00:00
Jaebaek Seo 1a5a6474d6 Support TargetPlatform.isJs() for FIR 2022-11-15 16:50:17 +01:00
Ilya Kirillov ed1751bbc6 [fir] move mutable/base collection pair map do StandardClassIds to further reuse it 2022-11-11 11:59:56 +01:00
Dmitriy Novozhilov 6623456d2a [FIR] Properly support @JvmRecord
^KT-53867 Fixed
2022-10-03 15:48:17 +03:00
Ilya Kirillov fdf826208f Fix FqName.startsWith for fqNames shorter when the segment 2022-09-30 12:19:35 +02:00
Mikhail Glukhikh a4b2a8c4ea AbstractTypeChecker: fix special case with CapturedType as self type argument
#KT-53908 Fixed
May fix also KT-53271
2022-09-19 19:12:21 +00:00
Abduqodiri Qurbonzoda f2b0c30cba Remove Experimental and UseExperimental from compiler OptIn usage checkers 2022-09-17 01:06:56 +00:00
pyos ecdd80769e FIR: do not read a Java nested class if the outer class is Kotlin
Example: if C is a Kotlin class and there is an import of C.Companion.f,
a call to f will need to check if it is a constructor, for which
it will attempt to load C.Companion.f as a Java class. This involves
loading all outer classes, including C itself, as BinaryJavaClass - see
KotlinCliJavaFileManagerImpl - despite the fact that C and C.Companion
have both already been loaded from their Metadata annotations as Kotlin
classes, wasting cycles and polluting caches.

Thus the theoretical motivation for this change is to marginally speed
up FIR.

The real motivation is that with the -Xemit-jvm-type-annotations option,
kotlinc sometimes generates invalid annotations, and reading them with
BinaryJavaClass throws an exception (the Kotlin metadata however is
valid):

    // MODULE: lib
    // FILE: C.kt
    // The constructor has an argument of type
    //   List<? extends Function1<? super String, Integer>>
    // and a ParameterName type annotation with path
    //   TYPE_ARGUMENT(0), TYPE_ARGUMENT(0)
    // which is missing a WILDCARD between the two TYPE_ARGUMENTs
    class C(val x: List<(name: String) -> Int>) {
      companion object {
        fun foo() {}
      }
    }
    // MODULE: main(lib)
    // FILE: main.kt
    import C.Companion.f

    fun bar() = foo() // crashes FIR

The parameter annotation should obviously be fixed too, but invalid
bytecode may already exist in the wild. Also, did I mention that this
change marginally speeds up FIR?
2022-09-16 08:44:15 +00:00
Mikhail Glukhikh e36091b926 K2: introduce even more readable renderer for types in messages
#KT-53343 Fixed
2022-09-13 09:05:48 +00:00