Commit Graph

108 Commits

Author SHA1 Message Date
Denis.Zharkov 05ca001310 FIR2IR: Repeat the K1 behavior: SAM conversion with 'in' projection
It would be more consistently to prohibit the behavior from the unmuted
test (see KT-52428), but it was decided to postpone the breaking change.

Unfortunately, it didn't work to make a test where for computing
star projections we would need to substitute other type parameters
because effectively, it's not allowed to have SAM conversion when
star projections/wildcard is based on a type parameter which bounds
use other type parameters.

^KT-53552 In progress
2023-02-20 14:54:09 +00:00
Dmitriy Novozhilov aef9b129d2 [FIR] Add regression tests for number of issues fixed in K2
List of issues:
KT-4113,  KT-6822,  KT-7389,  KT-17817, KT-20223
KT-21463, KT-24503, KT-24737, KT-24779, KT-24901
KT-27261, KT-28668, KT-30497, KT-30756, KT-36958
KT-37365, KT-37490, KT-38288, KT-41038, KT-41721
KT-42136, KT-42169, KT-42449, KT-42715, KT-43553
KT-43603, KT-43846, KT-43936, KT-46288, KT-46301
KT-47373, KT-47484, KT-47490, KT-47495, KT-47750
KT-47815, KT-47870, KT-48975, KT-49024, KT-49045
KT-50134, KT-50160, KT-50550, KT-51045, KT-51143
KT-51796, KT-52262, KT-52424, KT-52860, KT-52934
KT-53086, KT-53494, KT-53671, KT-53752, KT-53819
KT-54478, KT-54518, KT-54931, KT-54990, KT-55138
KT-55379, KT-55555, KT-56243
2023-02-14 17:08:55 +00:00
Sergej Jaskiewicz bd18fd40ea [K/N] Remap type args of SAM interfaces in FunctionReferenceLowering
#KT-56188 Fixed
2023-01-27 15:26:32 +00:00
Ilya Chernikov 78ca733c38 FIR JS: add K2 variants of all other JS tests
except tests that are not possible to add without some modifications in
the test infra. See todos on the commented-out test declarations
2022-11-12 16:28:24 +01:00
Ilya Chernikov 5b3816cce5 Test infra: refactor IGNORE_BACKEND directive
treat it as a general one, introduce *_K1 and *_K2 variants for
more specific ignoring
2022-11-12 16:28:23 +01:00
Alexander Udalov b42a7be0de Psi2ir: keep nullability when substituting function type for SAM type
After we added "careful approximation of contravariant projections" in
584b70719e, some SAM conversions started to require an additional
implicit cast of the functional value before it is converted to the SAM
interface. The target type of this implicit cast was computed
incorrectly because it didn't contain nullability of the SAM type. This
could lead to a situation where a nullable value was incorrectly cast to
a non-null type, which caused a missing null check and NPE at runtime.

For example, let's consider the test `kt54600.kt`. SAM conversion
happens in the constructor call `J(filter)`. Before 584b70719e, the IR
for that argument was (irrelevant things are omitted for simplicity):

  TYPE_OP SAM_CONVERSION type=Condition<String!>!
    GET_VAR filter type=Function1<String, Boolean>?

After 584b70719e, the IR became:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>
      GET_VAR filter type=Function1<String, Boolean>?

Note the two changes:
* The resulting SAM type changed from `Condition<String!>` to
  `Condition<Any?>`. This is exactly the point of the "careful
  approximation" change, because just erasing the "in" projection from
  the parameter type is incorrect, see the explanation for that change.
* The value is now implicitly cast to the _non-null_ function type
  before it is SAM-converted. The presence of the cast is fine, but the
  fact that it's to a non-null type is an oversight.

The target type for this cast is computed at
`KotlinType.getSubstitutedFunctionTypeForSamType` in psi2ir. Now it
extracts the nullability from the SAM type and retains it in the
resulting function type.

After this change, the IR for the argument becomes:

  TYPE_OP SAM_CONVERSION type=Condition<Any?>!
    TYPE_OP IMPLICIT_CAST type=Function1<Any?, Boolean>!
      GET_VAR filter type=Function1<String, Boolean>?

Note that the target type is now flexible, as the resulting SAM type.
Another option would be to make it nullable, as the type of the
functional value, but there doesn't seem to be any difference.

 #KT-54600 Fixed
2022-10-25 11:20:23 +00:00
Jinseong Jeon a2da690afd Test: add java source files as JavaSourceRoot
so that those can be properly populated in SingleJavaRootsIndex
2022-06-16 22:14:17 +02:00
pyos 27c51f5f88 JVM_IR: skip SAM lambdas when computing enclosing method of objects
This is what Java 15+ does, and it permits accessing captured type
parameters via reflection. The alternative is to emit generic signatures
on the lambda methods, but that was disabled and I have no clue why.

^KT-52417 Fixed
2022-06-08 23:59:58 +02:00
Mikhail Glukhikh 7c89f0188a FIR: resolve conflicts around SAM calls properly 2022-05-24 12:29:27 +00:00
Steven Schäfer 0da23198e6 JVM_IR: Add null-checks in SAM wrapper constructors (KT-50108) 2022-05-14 02:01:44 +02:00
Victor Petukhov 22b2554368 [FE 1.0] Support suspend only SAM conversions
^KT-50477 Fixed
2022-03-24 09:28:28 +00:00
Dmitry Petrov fdb01d96f0 JVM_IR JavaSamConversionEqualsHashCode 2022-03-03 09:01:42 +00:00
Ivan Kochurkin 58dfe3d804 [FIR2IR] Reify type parameters for callee reference with vararg 2021-12-21 19:10:41 +03:00
Dmitry Petrov 81c805a754 JVM_IR KT-50171 add missing parent to temporary vals for proxy fun 2021-12-11 15:51:12 +00:00
Victor Petukhov a6fd14d4e6 [FE 1.0] Eliminate resolution ambiguity on inherited SAM-interfaces
^KT-17765 Fixed
2021-11-22 14:18:30 +03:00
Mikhail Glukhikh cf104c8433 FIR: add status line to all failing black box tests 2021-11-20 03:37:31 +03:00
Ivan Kylchik c7435ba760 Replace all occurrences of WITH_RUNTIME with WITH_STDLIB
We are going to deprecate `WITH_RUNTIME` directive. The main reason
behind this change is that `WITH_STDLIB` directive better describes
its meaning, specifically it will add kotlin stdlib to test's classpath.
2021-11-17 15:26:38 +03:00
Alexander Udalov 1071919706 Remove backend tests on old inference
Also remove any mentions of NewInference, and rename some tests.
2021-11-09 20:07:33 +01:00
Igor Laevsky e331a52e75 [Wasm] Mute/unmute box tests after kotlin.test support 2021-10-14 17:24:05 +03:00
Dmitry Petrov 6ba65065ee JVM add tests for KT-48544 & KT-49226 2021-10-14 17:23:12 +03:00
Svyatoslav Kuzmich 9ef899ef10 [Wasm] Reuse Callable reference and SAM lowerings from JS 2021-10-08 07:24:41 +03:00
Svyatoslav Kuzmich aa5f98f919 [JS] Remove KJS_WITH_FULL_RUNTIME for tests that already have WITH_RUNTIME 2021-10-07 22:36:18 +03:00
Svyatoslav Kuzmich c88cde2f8b [Wasm] DONT_TARGET_WASM_BACKEND => IGNORE_BACKEND in testdata 2021-10-02 06:14:35 +00:00
Svyatoslav Kuzmich ab9a23cbfa [Wasm][Stdlib] Reuse K/N collections and StringBuilder 2021-10-01 17:18:49 +03:00
Dmitry Petrov c77884f067 Refactor SAM type handling, replace non-approximated arguments with * 2021-06-22 21:13:56 +03:00
Victor Petukhov 4aeabb6b0f Use upper bound aware type approximator for intersection types inside sam types in contravariant positions to build proper types in terms of subtyping 2021-06-22 21:13:55 +03:00
Alexander Udalov b2005302dc JVM, JVM IR: erase generic SAM supertypes
Also, do not try to use invokedynamic on SAM calls with intersection
types, because intersection type is not allowed as an immediate type
projection of a supertype, and constructing a fake override in
LambdaMetafactoryArgumentsBuilder led to an exception. This fixes the
problem which was worked around earlier in e6c089ef, effectively
reverting that commit.

The main motivation for this change is that LambdaMetafactory also
doesn't generate generic signature for SAM wrapper classes at runtime.
Since these classes are synthetic, nobody should rely on the fact that
they have generic supertypes, which was observable only via Java
reflection.

 #KT-46149 Fixed
 #KT-46238 Fixed
2021-04-22 10:53:15 +02:00
Alexander Udalov 7fe10e27a1 Minor, fix failing codegen tests on different JDKs
#KT-46238
2021-04-21 14:43:10 +02:00
Dmitry Petrov 59de12c609 Minor: mute bytecode text check in some box tests failing in FIR 2021-04-21 11:27:12 +03:00
Alexander Udalov e6c089ef40 IR: fix SAM conversion for types with contravariant intersection argument type
In the added test, the problem was that the SAM type as computed by
`SamTypeFactory.createByValueParameter` was `Consumer<{BaseClass &
BaseInterface}>`, which was latter approximated in psi2ir during the
KotlinType->IrType conversion to `Consumer<out Any?>` (here:
https://github.com/JetBrains/kotlin/blob/3034d9d791cf1f9033104e12448e0d262d3bc3ce/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt#L606),
because intersection type argument is approximated to `out Any?`.

To avoid this, replace intersection type in immediate arguments of a SAM
type with the common supertype of its components at the same place where
we're getting rid of projections.

 #KT-45945 Fixed
2021-04-20 17:31:14 +02:00
Dmitriy Novozhilov 7dc3be3b9b [FIR2IR] Replace star projections with upper bounds for SAM conversion types 2021-03-24 12:56:15 +03:00
Dmitry Petrov 0cca07fa19 Bump d8 used in box tests to 2.1.75 2021-03-10 21:04:12 +03:00
Alexander Udalov 628d75c7cd JVM: fix EnclosingMethod information for SAMs in inline lambdas
Pass parentContext to SamWrapperCodegen from the outside instead of
using the one from parentCodegen. The difference is that in case of an
inline lambda, we're creating an InlineLambdaContext whose parent is a
ClosureContext, but the codegen for that lambda has that latter
ClosureContext as its context. So the getNonInlineOuterContext call in
SamWrapperCodegen.generateInnerClassInformation wasn't able to identify
that this is a context of a lambda that needs to be skipped, and
generated it as EnclosingMethod, which caused Java reflection to fail
because once that lambda was inlined, it was removed and thus didn't
make it to runtime.

 #KT-44827 Fixed
2021-03-09 11:43:11 +01:00
Dmitriy Novozhilov da0fd7cc15 [FIR2IR] Approximate non-denotable types when converting ConeType to IrType 2021-03-02 19:11:21 +03:00
Dmitriy Novozhilov 7b7b8fbea7 [Test] Filter dependent modules by source kind in creating FirModuleInfo 2021-02-18 14:44:44 +03:00
Dmitry Petrov 6d019d9544 JVM_IR indy-SAM on functional expression 2021-02-17 22:18:06 +03:00
Dmitry Petrov 3ebeca5852 JVM_IR: use indy SAM conversions in jvmTarget 1.8+, fix bridges
KT-44278 KT-26060 KT-42621
2021-02-12 16:52:30 +03:00
Alexander Udalov 510b9e6f2a Move around some codegen box tests
In tests merged from boxAgainstJava in 29b96aa1, some directories were
named slightly differently compared to box, e.g. "property" vs
"properties", "varargs" vs "vararg". This change renames these, moves
some of the tests to more fitting directories, and also renames
"visibility" to "javaVisibility" because it's about Java visibilities
specifically.
2021-02-11 13:50:09 +01:00
Alexander Udalov 401f0ac583 Use TARGET_BACKEND instead of DONT_TARGET_EXACT_BACKEND in box against Java tests
"// TARGET_BACKEND: JVM" more clearly says that the test is
JVM-specific, rather than DONT_TARGET_EXACT_BACKEND which excludes all
other backends.
2021-02-11 13:50:08 +01:00
Mikhail Glukhikh 346ffb3acf FIR2IR: support substitution for SAM types 2021-02-11 11:48:34 +03:00
Mikhail Glukhikh 7050af9b79 FIR2IR: use invariant projections for SAM_CONVERSION types 2021-02-11 11:48:34 +03:00
Dmitriy Novozhilov 29b96aa15d [Test] Properly merge box against java testdata into codegen/box
Previous commit about it was 3199ce03 and it was completely wrong
2021-02-04 10:53:50 +03:00
Victor Petukhov 670f029bdf Allow passing non-spread arrays into a vararg parameter after sam properly, through propagating vararg element type to a sam adapter from the original parameter descriptor 2021-01-28 13:19:31 +03:00
Victor Petukhov af3eaf5d71 Add explicit disabling ProhibitVarargAsArrayAfterSamArgument feature in tests as it's enabled by default in 1.5 2021-01-28 13:19:31 +03:00
Jinseong Jeon 3bca6ae893 FIR: allow lower bound of flexible type when finding contributed invoke 2020-12-21 18:01:25 +03:00
Svyatoslav Kuzmich fdd7fa5aea [Wasm] Mute codegen box tests 2020-11-09 16:04:43 +03:00
Jinseong Jeon bc6693fa6e FIR2IR: element-wise SAM conversion for vararg 2020-10-13 15:40:06 +03:00
Alexander Udalov 2f86554d5a IR: don't produce fake overrides for static and private declarations
Note that only irrelevantStaticProperty.kt failed before this change.
Having private declarations caused no problems, but it seems incorrect,
so it's fixed now and irrelevantPrivateDeclarations is added just in
case.

 #KT-41848 Fixed
2020-09-12 20:01:34 +02:00
Mikhail Glukhikh 5efabe063e [FIR] Fix JVM mapped function callable id 2020-08-31 14:31:57 +03:00
Jinseong Jeon bff36e0199 FIR2IR: convert annotations on FirTypeRef 2020-07-30 11:25:36 +03:00