Commit Graph

96831 Commits

Author SHA1 Message Date
Dmitriy Novozhilov 9946bfcdfd [FIR2IR] Properly handle error references in generation of receivers
^KT-53698 Fixed
2022-12-09 12:02:06 +00:00
Dmitriy Novozhilov f3da26946b [FIR] Change priority of K2_VISIBILITY_ERROR CandidateApplicability
In K1 analogue of `K2_VISIBILITY_ERROR` is `K1_RUNTIME_ERROR`, so
  candidates with `K2_VISIBILITY_ERROR` should win over innaplicable
  candidates with `INAPPLICABLE`, `INAPPLICABLE_ARGUMENTS_MAPPING_ERROR`
  or `INAPPLICABLE_WRONG_RECEIVER` applicability

This is needed to allow resolution to invisible symbols (and later
  suppress error with `@Suppress("INVISIBLE_SYMBOL", "INVISIBLE_REFERENCE")`

^KT-55026 Fixed
^KT-55234
2022-12-09 12:02:05 +00:00
Dmitriy Novozhilov 6c6525ecde [FIR] Add test for KT-55026 2022-12-09 12:02:04 +00:00
Alexander Likhachev 0466fc536d [Gradle] Don't convert free compiler arguments to set, avoid args duplication
#KT-55363 Fixed
2022-12-09 10:59:14 +00:00
Alexander Likhachev a5810d88a5 [Gradle] Add an integration test for KT-55363 2022-12-09 10:59:14 +00:00
Pavel Mikhailovskii b31209a38a KT-51951 Add a test 2022-12-09 09:47:23 +00:00
Alexander Shabalin 01cabefea7 [K/N] Use configurations for interproject compdb deps ^KT-53776
Merge-request: KT-MR-7158
Merged-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>
2022-12-09 09:42:08 +00:00
Pavel Mikhailovskii 76997edebe KT-52373 Fix generation of synthetic functions with context receivers and default parameters 2022-12-09 09:39:26 +00:00
Sergey Bogolepov 4fa701f798 [K/N] Support caches and program outputs in dynamic driver
This commit mostly ports current phases "as-is", without any
moving them to an explicit I/O. It will be done later after static
driver removal.
2022-12-09 00:55:39 +00:00
Sergey Bogolepov bf89e27647 [K/N] Prepare dynamic driver for more output kinds
* Extract frontend and psi2ir into functions
* Prepare hacks for porting old phases to the dynamic driver
2022-12-09 00:55:38 +00:00
Troels Bjerre Lund bb1acf729b [K/N] Add custom allocator prototype ^KT-55364
Enable custom allocator with -Xallocator=custom.

If the gc is cms (default):
 * a patched version of the memory manager is used that does not build a
   list of allocated objects.
 * a patched version of the cms is used that defers to the allocator for
   sweeping.

Otherwise, a warning is printed, and the allocator is used using the
standard api.

Design doc:
https://docs.google.com/document/d/15xMp-nE-DWL8OrtOc8DoXB80AHUphFICEGjj5K0aNFc

Co-authored-by: Troels Lund <troels@google.com>

Merge-request: KOTLIN-MR-546
Merged-by: Alexander Shabalin <alexander.shabalin@jetbrains.com>
2022-12-08 17:22:04 +00:00
Evgeniy.Zhelenskiy 40f38c8adb [IR] Eliminate redundant boxing/unboxing of MFVC after inlining
Signed-off-by: Evgeniy.Zhelenskiy <Evgeniy.Zhelenskiy@jetbrains.com>

#KT-1179
2022-12-08 15:12:28 +00:00
Gleb Lukianets a3e396e7e4 [K/N] KT-53069: Guard against recursive generic type argument constraints during objc export
Merge-request: KT-MR-7872
Merged-by: Gleb Lukianets <Gleb.Lukianets@jetbrains.com>
2022-12-08 14:03:45 +00:00
Anton Lakotka 96e1ba045c [Gradle] Do not throw exceptions when getDependenciesTransformation...
is called. Some kotlin plugins (for example JS) re-use
DefaultKotlinSourceSet class for their source sets. However
DefaultKotlinSourceSet has an API that is connected to IDE import
particularly `getDependenciesTransformation`. Since Kotlin/JS doesn't
support metadata dependencies, and their transformations as well
we should lift strong requirement for compileDependenciesTransformation
to be set for each source set. Instead, just return empty list of
transformations.

^KT-55347 Verification Pending
2022-12-08 13:38:13 +00:00
Anton Lakotka 5347fc235b [Gradle, Test] GranularMetadataTransformation should be accessible in JS
Pure JS projects should still be able to import even thus calling
`getDependenciesTransformation` should not throw any runtime exceptions
and results should be empty. Since JS projects doesn't support metadata
dependencies transformations.

^KT-55347 In Progress
2022-12-08 13:38:13 +00:00
Egor Kulikov dbfe33c00d [FIR] Make default values for value parameters lazy in RawFirBuilder
Sixth step for ^KT-52615

Merge-request: KT-MR-7926
Merged-by: Egor Kulikov <Egor.Kulikov@jetbrains.com>
2022-12-08 13:32:37 +00:00
Marco Pennekamp dbb02a9bfb [FIR] Fir2IrJsResultsConverter: Compute hasErrors of backend input
- This allows us to re-enable 3 tests.
2022-12-08 13:01:17 +00:00
Zalim Bashorov 49c3ba33f1 [Wasm] Add a basic end-to-end sourcemap generation in wasm backend
More constructions/instructions will be supported separately.
2022-12-08 12:44:26 +00:00
Leonid Startsev 1c4614e93b Handle situation where KSerializer is absent from immediate supertypes
of the class used in @UseSerializers: Use methods to receive
full list of supertypes.

K1 supertypes() call returned all supertypes, while
IrClass.supertypes and FirClassSymbol.resolvedSuperTypes return only immediate ones.

This lead to a difference in behavior between K1 and K2, and regression
after plugin backend was rewritten from descriptors to IR.

#KT-55340 Fixed
2022-12-08 12:15:16 +00:00
Leonid Startsev c011f0c374 Change throw AssertionError to error() that throws IllegalStateException
as ISE is more appropriate exception for validation.

Improve SerializerClassLowering.runPluginSafe so precise IrClass
where plugin have failed can be reported for non-fatal errors.

#KT-55296 Fixed
2022-12-08 12:15:16 +00:00
Pavel Punegov 7ee877f9aa [K/N][test] Improve simulator executor
Makes executor be able to find and download necessary runtimes and
create device with appropriate runtime available. Replaces device names
with identifiers


Co-authored-by: Alexander Shabalin <Alexander.Shabalin@jetbrains.com>

Merge-request: KT-MR-7919
Merged-by: Pavel Punegov <Pavel.Punegov@jetbrains.com>
2022-12-08 11:11:00 +00:00
Yan Zhulanow c8e9cfde0b [FE] Read Java static field initializer lazily (KTIJ-23043) 2022-12-08 10:46:43 +00:00
Mikhail Mazurkevich dbddbab73c [jps] KT-55309 Inline storage initialization 2022-12-08 10:43:28 +00:00
Mikhail Mazurkevich dfead910b9 [jps] KT-55309 Remove obsolete NonCachingLazyStorage 2022-12-08 10:43:27 +00:00
Dmitriy Novozhilov 44fd9ddf85 [Test] Add test for KT-55338 2022-12-08 10:19:36 +00:00
pyos a3768b9185 FIR DFA: don't propagate reassignments of loop-scoped vars to outside 2022-12-08 10:19:36 +00:00
pyos 06b71f8300 FIR DFA: drop data flow edges from postponed lambdas in return values
This is a temporary hack to avoid compiler crashes in some code that
uses builder inference, conditional early returns from lambdas, and
expected types in a certain way. It is not correct - dropping data flow
edges never is - but it is much easier to implement for now than a
proper fix.
2022-12-08 10:19:36 +00:00
pyos f2347d1954 FIR DFA: use PersistentSet.Builder for exactType 2022-12-08 10:19:35 +00:00
pyos cc973f8c3f FIR DFA: merge LogicSystem and PersistentLogicSystem 2022-12-08 10:19:35 +00:00
pyos 9f4cfa2c50 FIR CFG: ignore exception edges when looking for return values
^KT-54668 Fixed
2022-12-08 10:19:34 +00:00
pyos 664a70ec13 FIR DFA: split flow for postponed lambdas from a single node
This removes the need for hacks around the order in which function
call arguments are visited, fixes called-in-place lambda arguments
for augmented assignment operators, and makes CFG dumps a bit prettier.
2022-12-08 10:19:34 +00:00
pyos 402ea98e02 FIR DFA: align FirLocalVariableAssignmentAnalyzer with the graph builder
I.e. maintain a set of seen lambdas where each marked as either "data
flow only" or "both data and control flow". The latter are truly
parallel with the function being analyzed, while the former have
technically already terminated, we just don't know the types inside them
because they may not have been analyzed yet.
2022-12-08 10:19:34 +00:00
pyos c231477375 FIR: don't call a graph builder method in finally
If an exception is thrown, trying to add more nodes to a graph that's
already missing entire subgraphs may not end well.
2022-12-08 10:19:33 +00:00
pyos 38c1ef30bc Minor: refactor FirPropertyInitializationAnalyzer
Still not sure how to implement visitUnionNode
2022-12-08 10:19:33 +00:00
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