Commit Graph

61 Commits

Author SHA1 Message Date
Kirill Rakhman 560c1cacf3 [FIR] Fix capturing of flexible types during resolution
Previously, because we didn't handle flexible types properly in
prepareCapturedType, projections inside flexible types would only be
captured during subtyping with captureStatus=FOR_SUBTYPING
which would lead to the constraint type being wrongly approximated
(see ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint).

Fixing the capturing produced two kinds of false positive diagnostics:

1. In ConstraintInjector.TypeCheckerStateForConstraintInjector
.addNewIncorporatedConstraint we would get two instances of cone types
that are structurally equal and containing the same captured type.
However, because we only skipped subtyping if the types were
referentially equal, we would get a contradiction here.
The fix was to use structural equality instead, which should be okay
as the captured type instances are the same.

2. Reified type variables were inferred to captured types because
flexible arrays with captured upper bounds
(Array<Foo>..Array<Captured(out Foo)>?) were not properly approximated.

#KT-62609 Fixed
2023-11-30 08:54:26 +00:00
Kirill Rakhman 5b9c35de2e [Tests] Update test data with error suppression warnings
#KT-61129 Fixed
2023-08-18 13:29:20 +00:00
Victor Petukhov 42e71f8c53 Remove explicit enabling the new type inference from test data 2022-07-22 16:03:52 +00:00
Victor Petukhov 224beb24eb Remove explicit disabling the new type inference from test data 2022-07-22 16:03:51 +00:00
Victor Petukhov b32887380a [FE] Move empty intersection tests into separate directory 2022-04-27 19:50:24 +00:00
Victor Petukhov e0a1f1c405 [FE] Review fixes 2022-04-27 19:50:24 +00:00
Victor Petukhov 47d6236a2d [FIR] Support determining emptiness of an intersection type with type parameters' types 2022-04-27 19:50:23 +00:00
Victor Petukhov b96708c3e2 [FE] Support reporting INFERRED_TYPE_VARIABLE_INTO_EMPTY_INTERSECTION for empty intersection types with type parameters 2022-04-27 19:50:21 +00:00
Victor Petukhov c16ae81a48 [FIR] Report errors for upper bounded type variables by an empty intersection type
^KT-51221 Fixed
2022-04-27 19:50:21 +00:00
Victor Petukhov 65213e9a42 [FE 1.0] Report warnings or errors for upper bounded type variables by an empty intersection type 2022-04-27 19:50:21 +00:00
Simon Ogorodnik 61ea65906c FIR: Implement captured type substitution 2021-12-15 22:22:58 +03:00
Denis.Zharkov 883b18a0c6 FIR: Preserve non-custom attributes after substitution
The test is being fixed since synthetic call for elvis has @Exact-attribute on return type
2021-11-26 19:39:45 +03:00
Victor Petukhov 758eb8f851 Fix builder inference tests 2021-05-28 15:36:22 +03:00
Victor Petukhov fd5169186e Update test for the builder inference and add new ones 2021-05-28 15:36:21 +03:00
Denis.Zharkov dac9d7b17a FIR: Mark a pack of tests (53) as FIR_IDENTICAL 2021-05-25 13:28:29 +03:00
Denis.Zharkov ddbdfafa79 Remove OI/NI attributes from test data 2021-05-25 13:28:27 +03:00
Denis.Zharkov 2ecba6ac39 Remove WITH_NEW_INFERENCE directive from all tests
This directive anyway does not make test run twice with OI, and with NI
It only once run the test with specific settings (// LANGUAGE)
and ignores irrelevant (OI or NI tags)
2021-05-25 13:28:26 +03:00
Denis.Zharkov da3233c47d FIR: Update test data (NEW_INFERENCE_ERROR)
Though these diagnostics look correct (the calls or constraint
systems indeed contain errors), more precise diagnostic kinds should be
chosen later.
2021-05-20 17:24:36 +03:00
Denis.Zharkov b94335dd1c FIR: Update diagnostics test data
Green code correctly became red
2021-05-20 17:24:30 +03:00
Dmitriy Novozhilov 7fb2bf00c5 Force resolve annotations in annotation checker
#KT-46173 Fixed
2021-04-19 14:32:36 +03:00
Dmitriy Novozhilov 1f0ecade34 [FIR] Transform annotations of type refs in body resolve stage
Also fix building CFG for annotation calls
2021-04-14 18:30:56 +03:00
Andrey Zinovyev 67505a0071 [FIR] Add FINAL_UPPER_BOUND checker 2021-04-05 14:51:44 +03:00
Dmitriy Novozhilov e6b5cb5216 [TD] Update diagnostics test data due to new test runners
Update includes:
- Changing syntax of `OI/`NI` tags from `<!NI;TAG!>` to `<!TAG{NI}!>`
- Fix some incorrect directives
- Change order of diagnostics in some places
- Remove ignored diagnostics from FIR test data (previously `DIAGNOSTICS` didn't work)
- Update FIR dumps in some places and add `FIR_IDENTICAL` if needed
- Replace all JAVAC_SKIP with SKIP_JAVAC directive
2020-12-16 19:52:25 +03:00
Victor Petukhov 0857b9c9e7 Rethink constraints incorporation
Namely, remove incorporation “otherInsideMyConstraint” to eliminate
constraint system redundancy and produce a potentially very large number
 of constructs.
Instead, introduce not so “spreadable” incorporation during variable
fixation (equality constraint with result type into other constraints).
^KT-41644 Fixed
^KT-42195 Fixed
^KT-42920 Fixed
^KT-42791 Fixed
^KT-41741 Fixed
2020-11-25 11:15:20 +03:00
Dmitriy Novozhilov 10e7c0f1b2 [TEST] Fix long literal in testdata broken in 4374c06 2020-09-23 15:22:03 +03:00
Dmitriy Novozhilov 4374c06537 [FIR] Approximate all integer literals which resolved in independent mode
#KT-42016
2020-09-23 14:05:10 +03:00
Victor Petukhov 379c6944a2 NI: extract diagnostics from partially resolved call instead of separately handling it including running all checks
^KT-37630 Fixed
^KT-35494 Fixed
2020-05-22 22:13:53 +03:00
Victor Petukhov 12db3d6e83 NI: remove separation of variable fixation order by constraint kind
The commit partially reverts ec4d9d2f1f

^KT-37914 Fixed
2020-05-20 22:37:30 +03:00
simon.ogorodnik f573719cc1 [FIR] Fix missing receiver type if anonymous function without label 2020-04-08 14:56:17 +03:00
Mikhail Glukhikh 8884cbe415 Introduce FIR_IDENTICAL for FIR vs old frontend tests #KT-36879 Fixed 2020-03-05 09:39:40 +03:00
Mikhail Zarechenskiy 4f74515508 [NI] Fix CST calculation for covariant type projections 2020-01-16 17:18:20 +03:00
Victor Petukhov 4309f53e11 NI: don't filter flexible types during CST calculation and force return as result the first of such types
^KT-35658 Fixed
2019-12-25 18:00:23 +03:00
Dmitriy Novozhilov 7fed7a840b [NI] Update some testdata broken in NI 2019-12-20 11:17:47 +03:00
victor.petukhov 2d5a05466d NI: Fix some unwanted exclusions constraints with remained corresponding optimization 2019-12-12 18:45:07 +03:00
Dmitriy Novozhilov 2536fa0cd5 [FIR-TEST] Add new testdata generated after changes in previous commit 2019-12-12 16:11:46 +03:00
Victor Petukhov 775eb67219 NI: Add constraints which contain constraining type without projection
^KT-32243 Fixed
^KT-35172 Fixed
2019-12-02 19:42:18 +03:00
Mikhail Zarechenskiy b30a9e1d3e [NI] Remove capturing from supertypes during computation of CST 2019-10-31 11:32:05 +03:00
Mikhail Zarechenskiy e0fb586aaf [NI] Don't loose diagnostic after type variable fixation
#KT-24488 Fixed
2019-10-31 11:32:02 +03:00
Mikhail Zarechenskiy ca8da22569 [NI] Improve CST algorithm to handle non-fixed variables
#KT-32456 Fixed
 #KT-32423 Fixed
 #KT-32818 Fixed
 #KT-33197 Fixed
2019-10-31 11:32:00 +03:00
Mikhail Zarechenskiy 932d84d568 Fix performance regression in NI by fixing totally incorrect hashCode
The actual problem was introduced in 4f1e85b468, note how `hashCode` is implemented:
```
var currentHashCode = cachedHashCode
if (currentHashCode == 0) return currentHashCode
...
```
It's a silly bug, there should be check `if (currentHashCode != 0) ...` because `0` is used a marker for "uncomputed value".

Now, in the commit 0219b86d06 I added map with `KotlinType` as a key and because of constant `hash` for `KotlinType`, we basically got `List` instead of `Map`, which caused this performance regression

 #KT-34063 Fixed
2019-09-30 10:22:30 +03:00
Mikhail Zarechenskiy 796cdea50e [NI] Require all proper constraints for Exact return type
Consider call `foo(bar())` where bar() returns some type variable `T`;
 We had a contract that call `bar` can be completed without completion
 of foo (type variables can be inferred from the current context) if `T`
 has at least one proper lower constraint (ProperType <: T).
 Indeed, new constraints can be added only as upper ones, so there is
 no need to grow constraint system.

 Unfortunately, we have Exact annotation that is used on return type of
 elvis. Now, consider the following situation:
 ```
 fun foo(a: Any) {}
 fun bar(e: T): @Exact T

 foo(bar("str"))
 ```

 Here, because of Exact annotation, constraint with `Any`-type will be
 added as an equal one => our prerequisite that there will be no new
 lower constraints is false. `bar("str")` is inferred to Any in OI,
 this seems conceptually wrong, but it's another topic of discussion.

 In NI we can't just grow constraint system to use outer call because
 of another important use-case:
 ```
 fun <T> generic(i: Inv<T>) {}

 fun test(a: Inv<*>?, b: Inv<*>) {
     generic(a ?: b)
 }
 ```

 Common constraint system for these two calls can't be solved
 (fundamentally) for this example, only if (a ?: b) and generic(result)
 are computed separately.

 So, to mitigate initial issue, we'll grow constraint system only if
 there is at least one non-proper constraint.

 #KT-31969 Fixed
2019-06-19 11:07:31 +03:00
Mikhail Zarechenskiy ca997de6a7 [NI] Test data to understand changes in the next commit
##KT-31969 In Progress
2019-06-19 10:47:05 +03:00
Mikhail Zarechenskiy 787a8bb9bd Revert "[NI] Disable capturing/approximation type in TypeSubstitutor with enabled NI"
This reverts commit 7c4101e21c.

 #KT-31866 Fixed
 #KT-31868 Fixed
 #EA-125401 Fixed
 #KT-25290 Open
2019-06-07 12:31:38 +03:00
Dmitriy Novozhilov 7c4101e21c [NI] Disable capturing/approximation type in TypeSubstitutor with enabled NI 2019-05-29 10:35:46 +03:00
Mikhail Zarechenskiy 848640253a Revert "[NI] Disable capturing/approximation type in TypeSubstitutor with enabled NI"
This reverts commit f20ec3e0a6.
2019-05-29 01:31:28 +03:00
Dmitriy Novozhilov f20ec3e0a6 [NI] Disable capturing/approximation type in TypeSubstitutor with enabled NI
There is added a new service named `SubstitutingScopeProvider`, that
  provides factory that creates captured types and approximator for them.
  In OI they are the same as before commit, for NI they are empty, because
  that approximation interferes with NI algorithm

That service is injected into function descriptors and property descriptors
  and used for creating `SubstitutingScope` with correct services

Also there is changed time when we approximate captured types in NI
  (after all call checkers)

#KT-25290 Fixed
2019-05-28 11:18:33 +03:00
Dmitriy Novozhilov b4c8c79931 [NI] Add check for non-null argument type in arguments check
#KT-31461 Fixed
2019-05-23 12:22:42 +03:00
Dmitriy Novozhilov 07394bd6d3 [NI] Add test for KT-30300 with complex constraint system problem 2019-05-15 13:42:36 +03:00
Mikhail Zarechenskiy 93e79afab4 [NI] Preserve nullability of resulting type from CST if it's possible
Consider common supertype of `S` and `Nothing`, where `S` has nullable
 upper bound or it's flexible. Before the fix, result was `S?`, which
 is correct but too conservative. Now, we'll preserve nullability of
 resulting type if it's already nullable.

 This happened because we were failing to find path of not-nullable
 types from `Nothing` to `S`, which should obviously exists by
 semantics of Nothing
2019-03-04 11:29:39 +03:00
Mikhail Zarechenskiy 9b3e17f0d7 [NI] Avoid building controversial systems by clipping extra constraints
#KT-23854 Fixed
2019-03-04 11:29:38 +03:00