Commit Graph

96797 Commits

Author SHA1 Message Date
pyos d66be3f82d FIR CFG: do not assume all arguments to inline funs are called in place
Only values for non-noinline, non-crossinline, functional type
parameters qualify.
2022-12-08 10:19:32 +00:00
pyos 39f88b9e87 FIR CFG: move the argument reordering hack to the expression transformer 2022-12-08 10:19:32 +00:00
pyos 9823473f63 Minor: remove a redundant transformArgumentList override 2022-12-08 10:19:32 +00:00
pyos c4c05f5248 FIR CFG: remove ordering from control flow through in-place lambdas
Old graph:

  arg -> lambda enter -> ... -> lambda exit -> lambda enter -> ... ->
   -> lambda exit -> call

New graph:

  arg -+-> lambda enter -> ... -> lambda exit -+-> call
       \-> lambda enter -> ... -> lambda exit -/
2022-12-08 10:19:31 +00:00
pyos 5dce772f0b FIR DFA: restructure handling of += to avoid losing data flow 2022-12-08 10:19:31 +00:00
pyos b2fe5831ed FIR DFA: use local function declaration nodes for non-argument lambdas 2022-12-08 10:19:30 +00:00
pyos 8a68eac5f1 FIR DFA: add a union node for property delegates
The delegate is resolved in context-dependent mode and thus can be an
incomplete call; if there is no `provideDelegate` method to complete it,
the result is effectively `val x$delegate = y.id()` where `id` is
`fun <T> id(x: T) = x`, except we don't get a real node for `id` so the
DFA edges from lambdas in `y` go who knows where.
2022-12-08 10:19:30 +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
pyos 99bebfa183 FIR DFA: merge non-conflicting aliases from union flows
E.g. after `f({ x = a }, { x })`, if `f` calls both lambdas in-place,
`x` should be aliased to `a` even though only one path does that.
2022-12-08 10:19:29 +00:00
pyos e79b595639 FIR DFA: attach PersistentFlow directly to nodes 2022-12-08 10:19:29 +00:00
pyos 8d2ac141c3 FIR DFA: split Flow into PersistentFlow and MutableFlow
The distinction is similar to persistent data structures and their
builders. Only the MutableFlow can be passed to LogicSystem for
modification; when it's ready, it can be converted into PersistentFlow
and attached to a CFG node.

The result is that the API is cleaner, the implementation is a bit more
neat, and hopefully the use of PersistentHashMap.Builder improves
performance a little. Also the node-to-flow map can now be removed in
favor of just storing PersistentFlow inside a node, seeing as it's
explicitly immutable and all that.
2022-12-08 10:19:28 +00:00
pyos e1f0566738 FIR CFG: refactor handling of boolean operators a bit
To reduce the number of functions in FirDataFlowAnalyzer.
2022-12-08 10:19:28 +00:00
pyos 16b8811697 FIR DFA: take all statements from ?. if result is non-null.
I.e. a?.f(b as T) != null => b is T.

This also allows to remove the copyAllInformationFrom hack by moving the
edge directly in the control flow graph.
2022-12-08 10:19:28 +00:00
pyos 3392e066df FIR DFA: add more called-in-place tests 2022-12-08 10:19:27 +00:00
pyos f485413cfd FIR DFA: x !is T? => x != null
^KT-22996 tag fixed-in-k2
2022-12-08 10:19:27 +00:00
pyos 02fedeb9ed FIR DFA: revalidate reassigned variables after loops
If a certain type statement is true on loop entry and all continue
paths, then it is also true on exit if the condition did not reassign
the variable.

^KT-7676 tag fixed-in-k2
2022-12-08 10:19:27 +00:00
pyos f9745bd3f1 FIR DFA: make continue jump to condition entry, not loop entry
It's also not a backwards jump in do-while, unless it's in the loop's
condition, which is a stupid "feature" IMO. As you can probably tell
from the comments added in this commit.
2022-12-08 10:19:26 +00:00
Mikhail Glukhikh 7e407585fc CODEOWNERS: don't require separate review of generated files 2022-12-08 10:18:05 +00:00
Mikhail Glukhikh 5db804023e K2: inline shouldRunSamConversionForFunction
Here I delete the function which should always return true for LV>=1.4.
See different SamConversionOracle implementations for K1
2022-12-07 22:09:21 +00:00
pyos e359658c55 Minor: slightly speed up isSamType for FIR IDE 2022-12-07 22:09:20 +00:00
pyos 1232346202 Minor: merge FirSamResolver and its only implementation 2022-12-07 22:09:20 +00:00
pyos 0d46dfc1ba FIR: fix substitution of type arguments in SAM type aliases
^KT-54730 Fixed
2022-12-07 22:09:20 +00:00
pyos 3253789093 FIR: move typealias SAM constructor computation to FirSamResolver 2022-12-07 22:09:19 +00:00
Mikhail Glukhikh 982e743774 Minor: simplify FirScope.processConstructorsByName and things around 2022-12-07 22:09:19 +00:00
Alexander Udalov a594434a95 Kapt+JVM_IR: do not run IR plugins in kapt mode
Because in kapt stub generation mode (aka ClassBuilderMode.KAPT3, aka
generateBodies=false in psi2ir), method bodies are not generated and
compiler plugins such as kotlinx-serialization might not expect that.

 #KT-54245 Fixed
2022-12-07 21:14:30 +00:00
Alexander Udalov 5848b2fde6 Kapt+JVM_IR: add IrKotlinKapt3IntegrationTest 2022-12-07 21:14:29 +00:00
Anton Lakotka 1d041b7ef4 [Gradle] Replace deprecated String::capitalize with capitalizeAsciiOnly
This should prevent issues when ascii characters are uppercased or
lowercased on users machines with their locales.

For example in Turkish locale:
* 'i' uppercases to 'İ'
* 'I' lowercases to 'ı'

^KT-38712 Verification Pending
2022-12-07 20:39:26 +00:00
Anton Lakotka 7ef858b2fe [Gradle, Test] Check gradle entity names for turkish 'I' or 'ı'
^KT-38712
2022-12-07 20:39:25 +00:00
Mark Mann 3592c87abf Fix enumeration of empty list in KotlinLikeDumper
In some cases where the Kotlin compiler encounters an exception, it attempts to print the contents of the file that it was compiling at the time. Sometimes the content contains symbols that aren't bound to implementations. When that happens the safe value parameters for a function are empty because none of them can be resolved, but the value parameter count is still non-zero because the function reference still has multiple params — this causes exception messages to fail with an error:

```
Exception in thread "main" java.lang.IllegalStateException: Problem with constructing exception message
```
This fixes the issue by only attempting to access the safe value parameters if the list is of the proper size.

KT-54012
2022-12-07 19:46:49 +01:00
Alexander Korepanov 9edaebf235 [JS IR] Enable DTS generation in IC
^KT-54398 Fixed
2022-12-07 18:05:53 +00:00
Alexander Korepanov d21cbfe02e [JS IR] Take into account the declaration annotations in IC hash
So the annotation modifications invalidate the caller.
2022-12-07 18:05:53 +00:00
Alexander Korepanov 0a35d84193 [JS IR] DTS generation refactoring
Keep a DTS fragment in JsIrProgramFragment
 for each file and build the module DTS from them.
2022-12-07 18:05:52 +00:00
Dmitriy Novozhilov 03a43e0dc0 Advance bootstrap to 1.8.20-dev-3737 2022-12-07 16:47:48 +00:00
Pavel Mikhailovskii 6db5f8ee7f KT-55123 Add a default constructor to "expect" JvmSerializableLambda 2022-12-07 16:41:11 +00:00
Alexander Shabalin 314edd7066 [K/N] Add clangFormat task for automatic patch formatting ^KT-53776
Merge-request: KT-MR-7880
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-12-07 14:46:55 +00:00
Dmitrii Gridin 5c9aa88617 [AA] KtModule#project shouldn't be null
^KT-55336
2022-12-07 14:18:44 +00:00
Pavel Kirpichenkov f0642d6c9a fixup! Fix configurations in dependency handler of KotlinWithJavaCompilation 2022-12-07 13:35:55 +00:00
Pavel Kirpichenkov 72120271b7 fixup! Fix configurations in dependency handler of KotlinWithJavaCompilation 2022-12-07 13:35:55 +00:00
Pavel Kirpichenkov 55c13d7c05 fixup! Fix configurations in dependency handler of KotlinWithJavaCompilation 2022-12-07 13:35:55 +00:00
Pavel Kirpichenkov 786ea79886 [MPP] add tests for source set constraints
KT-54974
2022-12-07 13:35:54 +00:00
Zalim Bashorov 54c00cc588 [Sourcemap] Add an ability to provide outputColumn to SourceMap3Builder#addMapping instead of using getCurrentOutputColumn
The ability will be used later by wasm backend while generating sourcemap.
2022-12-07 12:03:54 +00:00
Zalim Bashorov fb4dcc6a6a [Sourcemap] Introduce getCurrentColumn and stop using TextOutput directly
The general goal is remove dependency on TextOutput and
make it simpler to use for wasm backend.
2022-12-07 12:03:54 +00:00
Zalim Bashorov e34d3d09bc [Sourcemap] Extract addLink from SourceMap3Builder as a addSourceMappingURL
The general goal is remove dependency on TextOutput and
make it simpler to use for wasm backend.
2022-12-07 12:03:54 +00:00
Dmitrii Gridin 9f82c43b1b [SLC] replace requireNotNull with regular exception
^KT-54051
2022-12-07 11:53:13 +01:00
Bogdan Mukvich c02d5e8dcc Make maven dependencies provided in kotlin-maven-plugin
KTI-1028
2022-12-07 10:28:48 +00:00
Bogdan Mukvich cffeb58ec3 Update maven dependencies in kotlin-maven-plugin
KTI-1028
2022-12-07 10:28:48 +00:00
Pavel Mikhailovskii 4676072137 KT-51284 Fix SAM conversion for methods with context receivers 2022-12-07 09:01:21 +00:00
Dmitrii Gridin cc9beb466e [SLC] SymbolLightClassForEnumEntry: shouldn't be regular class
^KTIJ-23842 Fixed
2022-12-07 08:41:19 +00:00
Bogdan Mukvich 2405dd2c5c Fix flaky behaviour of testThirdPartyCopyrights
KTI-1050
2022-12-07 08:20:47 +00:00
Pavel Mikhailovskii 2d69fd5a8a KT-52027 Encapsulate and fix calculation of parameter indices 2022-12-06 23:16:11 +00:00