90 Commits

Author SHA1 Message Date
Alexander Udalov d757847ed6 JVM: enable -Xlambdas=class for some backend tests
These tests are checking the specifics of the class-generated lambdas.
2023-05-12 15:21:00 +00:00
Ilmir Usmanov 84ccf412cb Minor. Ignore some tests on old JVM, JS_IR, JS and WASM
#KT-32162
2022-02-15 08:11:18 +01: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
Mikhael Bogdanov a657e63dbb Update test affected by ForbidUsingExtensionPropertyTypeParameterInDelegate feature 2021-07-16 13:26:35 +00:00
Ilmir Usmanov b33774e5f2 IC mangling: Use empty list as a separator in the new mangling scheme 2020-11-19 17:39:28 +01:00
Ilmir Usmanov 488d4ab018 IC mangling: Use '_' instead of 'x' as a placeholder before hashing 2020-11-19 17:39:27 +01:00
Ilmir Usmanov c62093f54c IC mangling: Change mangling rules
1. Use 'x' for each parameter, which is not an inline class, every
possible clash is handled by signature rather than name. This change
makes more API changes binary-compatible. So, the changes are in line
with the vision of inline classes are value classes, like primitives.

2. Take return type into account when mangling a function if the return
type is inline class. Otherwise, boxing bridge will not be generated,
which leads to CCE at runtime.
2020-11-19 17:39:24 +01:00
Steven Schäfer dc0ef996b7 JVM IR: Implement the new inline class ABI 2020-05-28 18:00:35 +03:00
Dmitry Petrov c165b8d55c JVM: Update IR bytecode text and signature tests 2020-05-20 07:19:30 +03:00
Dmitry Petrov cf70c83ab7 JVM: Update tests 2020-05-20 07:19:29 +03:00
Kristoffer Andersen 55aafb3430 [JVM IR] Support Suspend Main
This adds supports for (parameterless) suspend main entry points for
the JVM IR backend.

In case main is a suspend function, it gains a continuation during
lowering, so we simply generate a plain old `public static void
main(String[] args)`. This entry point invokes `suspend main` via
`kotlin.coroutines.jvm.internal.RunSuspendKt#runSuspend`.

This PR introduces `runSuspend` as a built-in, and generates the
following `main`, passing `args` as appropriate:

```
fun main(args: Array<String>) {
  runSuspend { main(args) }
}
```

The phase ordering has been reshuffled countrary to previous
discussion on #2780, as the MainMethodGeneration pass now introduces lambdas in
the IR. Hence, it has to run before InventNamesForLocalClasses, yet
still after JvmOverloadsAnnotations.

Some dead code was discovered in AddContinuationLowering
2020-02-21 12:00:47 +01:00
Steven Schäfer 07737f8fc6 JVM IR: Fix BridgeLowering 2020-02-07 18:44:50 +03:00
Kristoffer Andersen 4dd794c2d2 [JVM_IR] Propagate Type Parameters to DefaultImpls
This ensures correct generation of generic signatures in the resulting
byte code, but it _is_ a work in progress: the actual type *arguments*
passed for these parameters during compilation are dummy `Any?` types.

Sites that need more work are indicated with TODO's.

- copy type parameters of interfaces to methods moved to DefaultImpls
- implement type parameter renaming scheme from JVM, with proper
  renaming and substitution.
- adjust call sites in bridges in classes->DefaultImpls
- adjust call sites in bridges from DefaultImpls->Interface
- adjust call sites in bridges from DefaultImpls->DefaultImpls
- adjust super calls ->DefaultImpls
- adjust calls in code of Interfaces->DefaultImpls
2020-02-04 17:41:31 +03:00
Kristoffer Andersen f262f61096 [JVM + IR] Fix Generic Signature Test Expectations 2020-01-29 17:14:41 +01:00
pyos 7cd55c85e6 JVM/JVM_IR: fix mapping of KClass in annotation classes
* JVM incorrectly mapped T<KClass<...>> to T<Class<...>> because the
   annotation-ness of the type mapping mode was inherited one level
   down into a generic signature independent of T

 * JVM_IR was even worse as it did not use VALUE_FOR_ANNOTATION at all,
   mapping T<T<KClass<...>> to T<T<Class<...>> as well.

The correct behavior is to map KClass to Class only at top level or as
an argument of Array.
2019-12-03 11:42:23 +01:00
Mads Ager 15ed342282 JVM_IR: Generate args check in existing methods for special bridge methods.
Fix the number of arguments checked (1 for getOrDefault and 2 for
remove).
2019-11-19 19:10:04 +03:00
Steven Schäfer f9ff3771e5 JVM IR: Avoid getTopLevelClass in AddContinuationLowering 2019-11-07 13:48:43 +01:00
Kristoffer Andersen 28b6913a25 JVM IR: Support parameterless main methods
This commit:

- introduces tests explicating what is and isn't considered a
  proper main method on the JVM backends.
- implements support for parameterless main methods on the JVM IR
  backend
- See KT-34338 for more tests.
2019-10-21 15:08:34 +02:00
Alexander Udalov 22f8b9f475 Remove codegen tests on inline classes based on type parameters
According to KT-23819, such inline classes are prohibited. These tests
can be restored (and fixed if needed) as soon as we allow this back
2019-08-27 11:01:08 +02:00
Mikhail Zarechenskiy 80acc56c10 Don't lost type parameters for members of inline classes in the bytecode
#KT-33157 Fixed
2019-08-06 17:53:08 +03:00
Alexander Udalov cfd3d974d1 JVM IR: perform substitution in IrTypeSystemContext.getSubstitutedUnderlyingType 2019-08-05 21:27:20 +02:00
Alexander Udalov 5f06c9e86c JVM IR: do not generate generic signature for $delegate field
See ee7bbbf530
2019-08-05 21:27:20 +02:00
Alexander Udalov 45f93521d9 JVM IR: add IrWriteSignatureTestGenerated 2019-08-05 21:27:20 +02:00
Alexander Udalov a2612c1eae Fix generic signature for KSuspendFunction types in bytecode
#KT-27560 Fixed
2018-11-12 18:53:23 +01:00
Dmitry Petrov ab90b2b901 Fix nullability propagation in inline class type mapping
#KT-27096

See https://jetbrains.slack.com/archives/C06E082M6/p1537949572000100
2018-09-28 10:46:42 +03:00
Dmitry Petrov 8158dd0c83 Update testData for writeSignature tests 2018-09-07 10:25:59 +03:00
Dmitry Petrov 99498eb7b8 Use 'name-hash' mangling scheme
'-' is allowed as a name character both in JVM and in Dalvik, but can't
be a part of a Java identifier.
2018-08-30 14:58:52 +03:00
Dmitry Petrov a56d1d3ce8 Mangle function names with inline class parameters
Avoid name clashes in cases such as

  inline class Login(val login: String)
  inline class Password(val password: String)

  fun validate(login: Login) { ... }
  fun validate(password: Password) { ... }
2018-08-30 14:58:50 +03:00
Mikhael Bogdanov ca5b19d0c6 Merge Java 8 write signature tests in common ones 2018-08-27 15:55:03 +02:00
Mikhael Bogdanov efd93670f8 Migrate AbstractWriteSignatureTest.kt to CodegenTestCase stuff 2018-08-27 15:17:25 +02:00
Dmitry Petrov b6e3218ca2 Use mapping mode for inline class underlying type without wrapping 2018-08-16 15:03:50 +03:00
Mikhail Zarechenskiy ddf6c37e0e Prohibit inline classes with special underlying types
#KT-25328 Fixed
 #KT-23819 Fixed
2018-08-06 10:56:05 +03:00
Mikhail Zarechenskiy d606e5bc89 Correct boxing for functional types containing inline classes 2018-02-13 13:16:43 +03:00
Mikhail Zarechenskiy a8a9f774d0 Map inline classes in generic argument position to theirs wrap classes 2018-02-13 13:16:43 +03:00
Mikhail Zarechenskiy 4eb64fb4b9 Support mapping for inline classes based on type variables 2018-02-09 04:56:41 +03:00
Mikhail Zarechenskiy 928a342ace Initial version of codegen for inline classes 2018-02-05 12:07:40 +03:00
Mikhail Zarechenskiy d1049e5553 Refine type mapping for nullable inline class types 2018-02-05 12:07:39 +03:00
Mikhail Zarechenskiy d5400f11a3 Basic inline class mapping to the underlying representation 2018-02-05 12:07:39 +03:00
Mikhail Zarechenskiy a0d7b703f4 Align generic signature for inner classes to work as in Java
#KT-10397 Fixed

According to JVMS (p. 4.3.4) inner classes should be separated with `$` in generic signature.

Note that in Java, inner types separated with `.` after first parameterized type, and now we preserve the same behaviour. See tests for clarification.
2017-04-27 15:47:28 +03:00
Alexander Udalov 0dbb02ec6a Fix generic signature for KFunctionN types on JVM
#KT-15473 Fixed
2017-01-11 13:15:24 +03:00
Michael Bogdanov f8e9922c9e Don't generate generic signature for get/set methods in property reference class 2016-10-10 14:17:50 +03:00
Mikhael Bogdanov cd6b709ef5 'bytecodeText' test for synthetic accessor generic signature converted to 'writeSignature' test 2016-05-04 17:07:48 +03:00
Mikhael Bogdanov ee7bbbf530 Fix for KT-12127: Undeclared type variable on delegated property backing field
#KT-12127 Fixed
2016-05-04 17:07:48 +03:00
Michael Bogdanov 534a3a11d6 Write additional type parameters for DefaultImpls methods, fix for KT-11121: BadClassFile exception for interface implemented generic properties
#KT-11121 Fixed
2016-03-03 16:11:31 +03:00
Denis Zharkov 23d2b87a52 Ignore redundant projections for declaration-site variance 2016-01-14 19:20:00 +03:00
Denis Zharkov 154657a374 Fix wildcards for invariant arguments
See test with Java, we want preserve the invariant that if return type and
value parameter types are same in Kotlin, than we can use such return-value
as argument for that parameter
2015-12-15 16:18:31 +03:00
Zalim Bashorov 1e0b133e19 Find Nothing only in own arguments of generic type to make type raw and generate ''?" for contravariant position instead of use raw type 2015-12-07 19:25:59 +03:00
Denis Zharkov 303c756302 Refine generic signature for fields
- For vals use the same semantics as for return types
- For vars use the same semantics as for value parameters
2015-12-01 08:21:01 +03:00
Denis Zharkov ddb67d6c9c Support JvmSuppressWildcards and JvmWildcard annotations
#KT-9898 Fixed
2015-12-01 08:21:00 +03:00
Denis Zharkov 406e31f54a Change default rules for declaration-site wildcards
Mostly this commit is about skipping wildcards that are redundant in some sense.
The motivation is that they looks `long` in Java code.

There are basically two important parts: return types and value parameters.

1. For return types default behaviour is skipping all declaration-site wildcards.
The intuition behind this rule is simple: return types are basically used in subtype position
(as an argument for another call), and here everything works well in case of 'out'-variance.
For example we have 'Out<Out<T>>>' as subtype both for 'Out<Out<T>>>' and 'Out<? extends Out<? extends T>>>',
so values of such type is more flexible in contrast to `Out<? extends Out<? extends T>>>` that could be used only
for the second case.

But we have choosen to treat `in`-variance in a different way: argument itself
should be rendered without wildcard while nested arguments are rendered by the rules
described further (see second part).

For example: 'In<Out<OpenClass>>' will have generic signature 'In<Out<? extends OpenClass>>'.
If we omit all wildcards here, then value of type 'In<Out<OpenClass>>'
will be impossible to use as argument for function expecting 'In<? super Out<? extends Derived>>'
where Derived <: OpenClass (you can check it manually :]).

And this exception should not be very inconvinient because in-variance is rather rare.

2. For value parameters we decided to skip wildcards if it doesn't make obtained signature weaker
in a sense of set of acceptable arguments.

More precisely:
    a. We write wildcard for 'Out<T>' iff T ``can have subtypes ignoring nullability''
    b. We write wildcard for 'In<T>' iff T is not equal to it's class upper bound (ignoring nullability again)

Definition of ``can have subtypes ignoring nullability'' is straightforward and you can see it in commit.

 #KT-9801 Fixed
 #KT-9890 Fixed
2015-12-01 08:20:59 +03:00