Commit Graph

102768 Commits

Author SHA1 Message Date
Ilya Kirillov 24db4e62f5 Migrate some FIR/Analysis API KotlinExceptionWithAttachment usages to buildErrorWithAttachment API 2023-07-18 11:49:21 +00:00
Ilya Kirillov 24f60a542d Add basic test for getElementTextWithContext 2023-07-18 11:49:21 +00:00
Ilya Kirillov 743662ec7f [FIR] remove user code leaks from compiler.fir.java module, add more information to some errors 2023-07-18 11:49:21 +00:00
Ilya Kirillov e6c8bf6644 [FIR] remove user code leaks from compiler.fir.providers module, add more information to some errors 2023-07-18 11:49:21 +00:00
Ilya Kirillov 9f847da13e [FIR] remove user code leaks from compiler.fir.raw-fir module, add more information to some errors 2023-07-18 11:49:21 +00:00
Ilya Kirillov d43057e19a [FIR] remove user code leaks from compiler.fir.resolve module, add more information to some errors 2023-07-18 11:49:21 +00:00
Ilya Kirillov df0662459b [FIR] remove user code leaks from compiler.fir.semantics module, add more information to some errors 2023-07-18 11:49:21 +00:00
Ilya Kirillov b5394d79b9 [FIR] remove user code leaks from compiler.fir.tree module, add more information to some errors 2023-07-18 11:49:20 +00:00
Ilya Kirillov a9cd881a07 [FIR] add utilities to FIR compiler to throw error with attachment 2023-07-18 11:49:20 +00:00
Ilya Kirillov c5014d4765 Move PsiElement.getElementTextWithContext to psi module with small adjustments
* replace existing function (the new one makes it more clear which element was printed)
* prints position for element
* handles invalid psi element
2023-07-18 11:49:20 +00:00
Ilya Kirillov 4b3bff3344 Rework checkWithAttachment/requireWithAttachment
* better naming
* throw corresponding KotlinIllegalStateExceptionWithAttachments/KotlinIllegalArgumentExceptionWithAttachments instead of general KotlinRuntimeExceptionWithAttachments
2023-07-18 11:49:20 +00:00
Ilya Kirillov 2d791eb292 Rename buildErrorWithAttachment -> errorWithAttachment to emphasise the similar semantics to kotlin.error 2023-07-18 11:49:20 +00:00
Ilya Kirillov e3c31e1387 Introduce exception-specific exception classes for KotlinExceptionWithAttachments 2023-07-18 11:49:20 +00:00
Ilya Kirillov 52c065b08a Extract a base class from KotlinExceptionWithAttachments 2023-07-18 11:49:20 +00:00
Ilya Kirillov 15f6fe2627 Move ExceptionAttachmentBuilder near KotlinExceptionWithAttachments so it's accessible from KotlinExceptionWithAttachments 2023-07-18 11:49:20 +00:00
Ilya Kirillov 25911b1fec Move SmartPrinter to kotlin.core.util.runtime so it's accessible from KotlinExceptionWithAttachments 2023-07-18 11:49:20 +00:00
Ilya Kirillov 6f429ec072 [Analysis] migrate ExceptionAttachmentBuilder to use SmartPrinter
So it can be moved to a compiler module
2023-07-18 11:49:20 +00:00
Alexander Udalov 1cb1420e43 JVM: push down implicit coercion to Unit in IR
This is basically a workaround for a slightly different IR generated by
fir2ir vs psi2ir. Simplified, psi2ir generates something like this for
the sample from KT-59218:

  TRY type=Unit
    try: BLOCK type=Unit
      VAR methodHandle [...]
      TYPE_OP type=Unit origin=IMPLICIT_COERCION_TO_UNIT
        CALL invokeExact [...]

While fir2ir generates the following:

  TYPE_OP type=Unit origin=IMPLICIT_COERCION_TO_UNIT
    TRY type=Any?
      try: BLOCK type=Any?
        VAR methodHandle [...]
        CALL invokeExact [...]

The lowering relies on the fact that a polymorphic call (`invokeExact`
in this case) is a direct argument to the TYPE_OP, to determine the
correct return type (Unit in this case) to be generated in the bytecode.

The solution here is to push the type coercion "through" all the
block-like structures (`try`, `when`, container expression) so that if
the last statement in the block is a polymorphic call, it gets properly
converted even if the whole block is under a type coercion operation, as
it happens in fir2ir. We achieve that by using the "data" parameter of
the IR transformer: appropriate immediate children of
IrTypeOperatorCall/IrTry/IrWhen/IrContainerExpression get the type that
the expression needs to be coerced to, and all the other expressions
ignore that type and set it to null when transforming their children.

A proper solution would be to ensure fir2ir generates exactly the same
IR as psi2ir (KT-59781), but since PolymorphicSignatureLowering is the
only lowering affected so far, and polymorphic calls occur very rarely,
it seems safe to workaround it in the lowering for now.

 #KT-59218 Fixed
2023-07-18 11:37:42 +00:00
Alexander Udalov 69059362b8 Fir2Ir: generate 'finally' block always with Unit type
This is important for IR lowerings like PolymorphicSignatureLowering
which are very sensitive about the correct types of expressions and
placement of coercions to Unit (KT-59218).

A boolean parameter to `insertImplicitCasts` is not the best solution to
ensure that coercion to Unit is added. The best solution would be to fix
the TODO and generate coercion to the block's type for the last
statement. But that will affect many other places and will need to be
done separately => KT-59781.

Code in IrInterpreter is uncommented to fix the FIR test
`compiler/testData/ir/interpreter/exceptions/tryFinally.kt`; otherwise
evaluation of the function `returnTryFinally` there crashes with
"NoSuchElementException: ArrayDeque is empty". No idea why this test
didn't fail for K1 though, since the created IR is exactly the same.

For some unknown reason this breaks WASM backend with K2, but not with
K1 => KT-59800.
2023-07-18 11:37:41 +00:00
Alexander Udalov 79fa2b6db0 Fir2Ir: generate coercion to Unit for when branches if needed
Before this change, it could happen that `when` of type Unit has a
branch whose type is not Unit. This can lead to problems in IR
lowerings, for example PolymorphicSignatureLowering which is very
reliant on the correct types of expressions and placement of coercions
to Unit (KT-59218).
2023-07-18 11:37:41 +00:00
Alexander Udalov 5513740659 Minor, remove extraneous box tests
These tests are already present in
`compiler/testData/codegen/box/classes/kt496.kt`.
2023-07-18 11:37:41 +00:00
Sergej Jaskiewicz e6c4a8957d [IR] Make IrPropertyWithLateBinding a subclass of IrProperty 2023-07-18 10:19:27 +00:00
Ilya Kirillov 4b523825be [Analysis API] forbid providing custom KtLifetimeToken for every analyze call
^KT-60488 fixed
2023-07-18 08:47:34 +00:00
Dmitrii Krasnov b617b24d48 Bump Kotlin/Native version in KGP to 1.9.20-dev-6473.
This version allows the konan data dir to be configured via properties.

#KT-50463
2023-07-18 10:12:51 +02:00
Vladimir Sukharev f9df4e1487 [K/N] Reorder hashCode, toString, equals in data classes to match K1 order
^KT-60247 Fixed

Merge-request: KT-MR-11080
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-07-18 00:06:48 +00:00
Sebastian Sellmair a4a0da267e [Gradle] KotlinJvmCompilation: Implement 'javaSourceSet' as safe Future<SourceSet?>
^KT-60441 Verification Pending
2023-07-17 22:22:02 +00:00
Sebastian Sellmair a49db89024 [Gradle] CompletableFuture: Add 'isCompleted' API
^KT-60441 Verification Pending
2023-07-17 22:22:02 +00:00
Sebastian Sellmair 0feecebc07 [Gradle] jvm().withJava(): Fix Zombie compilation instance returned from create()
^KT-60462 Verification Pending
2023-07-17 22:22:01 +00:00
Zalim Bashorov 0945968751 [Wasm] Update expected size in test data 2023-07-17 23:57:35 +02:00
Zalim Bashorov b34d291f85 [Wasm] Turn on final types in V8 for the box tests 2023-07-17 23:57:35 +02:00
Zalim Bashorov 1cf3841588 [Wasm] Always use -0x30/sub when defining a struct type
Otherwise, according to the spec, a type will be treated as a final,
which is not correct in many cases.
Later, we can generate final struct types when it's applicable.

#KT-60200 Fixed
2023-07-17 23:57:34 +02:00
Zalim Bashorov 5db493a475 [Wasm, JS] Update v8 to 11.7.186 2023-07-17 23:57:34 +02:00
Zalim Bashorov b744f2ef82 [Wasm] Stop using "--type-ssa" since without "--type-merging" it increases output size
"--type-merging" was disabled before because it requires "--close-world"
which we can't use in general (specifically in Compose applications).
2023-07-17 23:57:34 +02:00
Dmitriy Dolovov ce815968cf [Native][tests] Use convention fun generatedTestDir() in build.gradle.kts 2023-07-17 21:09:40 +00:00
Dmitriy Dolovov 938146749d [PL][tests] K/JS: Avoid any unexpected warnings to appear in tests 2023-07-17 21:09:40 +00:00
Dmitriy Dolovov 715aba3d18 [PL][tests] K/JS: Run compiler through CLI interface 2023-07-17 21:09:40 +00:00
Dmitriy Dolovov 19c6208cc0 [PL][tests] K/N: Avoid any unexpected warnings to appear in tests 2023-07-17 21:09:40 +00:00
Dmitriy Novozhilov 8cae224cb4 [PSI2IR] Remove unused method 2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 01661da7aa [IR] Mark SymbolTable.descriptorExtension with @ObsoleteDescriptorBasedAPI 2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 11974c14d8 [IR] Fix various TODOs in SymbolTable 2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 73b580572b [FE] Move @PrivateForInline optIn into :core:compiler.common
This is needed to be able to use it in backend modules too
2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 49a1dfa20e [IR] Don't create packageFragment in IR builtins if not needed
In REPL it's possible that builtins will be created several times with
  the same symbol table. And since IrBuiltinsPackageFragmentDescriptorImpl
  has overridden equals, symbol for external package will be the same for
  different descriptors (with same FQN). So we should create IrExternalPackageFragment
  here only if it was not created before, on previous compilation
2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 899e95ea04 [IR] Include signature into error messages about symbols binding 2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 4ec65ace1c [IR] Update inheritors of SymbolTable which override some descriptor-related methods 2023-07-17 21:02:40 +00:00
Dmitriy Novozhilov 8ad202eb8b [IR] Remove descriptor-related methods from SymbolTable
Replace them with calls to SymbolTableExtension
2023-07-17 21:02:39 +00:00
Dmitriy Novozhilov b886b7488d [IR] Remove descriptor-related methods from ReferenceSymbolTable
Replace them with calls to ReferenceSymbolTableExtension
2023-07-17 21:02:39 +00:00
Dmitriy Novozhilov 4986cb14aa [IR] Extract descriptor part from SymbolTable into separate component
After this change SymbolTable (and ReferenceSymbolTable) contains only
  methods with IdSignatures. All descriptors-related methods are moved
  into DescriptorSymbolTableExtension, which automatically delegates to
  the SymbolTable if needed

At this moment there are cross-references between SymbolTable, because
  descriptor API is still actively used across backends. So SymbolTable
  is accessible in some place then descriptor extension will be accessible
  too

DescriptorSymbolTableExtension is an implementation of abstract SymbolTableExtension
  which allows to implement different kinds of storages, e.g. FIR based
  (it probably will be needed for FIR2IR)
2023-07-17 21:02:39 +00:00
Dmitriy Novozhilov 0067eb85da [IR] Drop unused methods of ReferenceSymbolTable 2023-07-17 21:02:39 +00:00
Dmitriy Novozhilov 36de30a694 [FIR2IR] Don't use SymbolTable for storing IR package fragments
This is needed for getting rid of usages of descriptors API from symbol
  table in K2
2023-07-17 21:02:39 +00:00
Sergey.Shanshin a45fe2d8a8 [KxSerialization] Implemented generation of companions for interfaces
For interfaces with custom serializer (@Serializer(`SerializerType::class)`) now the `serializer()` function is generated in the companion so that user can get a serializer by type

Merge-request: KT-MR-11040
Merged-by: Sergey Shanshin <Sergey.Shanshin@jetbrains.com>
2023-07-17 19:44:01 +00:00