Commit Graph

524 Commits

Author SHA1 Message Date
Denis Zharkov e54d2c7c32 Support named arguments in their own position
^KT-7745 In Proggress
2019-10-02 11:13:15 +03:00
Denis Zharkov f91db5f0b8 Restore correct overloads ambiguity accidentally removed in 1.3.60
This problem is only relevant when isTypeRefinementEnabled == true (HMPP projects)

Ambiguity accidentally was removed after 471134d
There, for areCallableDescriptorsEquivalent we stopped assuming
as impossible a situation of having identity-different descriptors
in the same containing declaraton that still might be considered equal

So, before 471134d we were comparing
"fun foo(x: String)" with "[substituted] fun foo(x: String)"
and areCallableDescriptorsEquivalent returned false for such case.
Thus, both overrides were left in the resulting set.

After 471134d, those two descriptors
becamed considered as equal thus having a possibility to remove any of them.

The problem is that "areCallableDescriptorsEquivalent" has kind of
unclear contract. Effectively it checks whether two descriptors match
to the same declaration.

But some of the usages expect that it also makes sure that descriptors
have the same substitution (see org.jetbrains.kotlin.resolve.calls.smartcasts.IdentifierInfo.Variable#equals)

So, the straight solution is using original descriptors for the cases
where we need to make sure that descriptors relates to actually different
declarations

^KT-34027 Fixed
2019-09-30 20:09:42 +03:00
Denis Zharkov 67410f7a57 Parametrize behavior of DescriptorEquivalenceForOverrides::areCallableDescriptorsEquivalent
The changes introduced 471134d31e are only needed
for the case of HMPP project while for other cases it might break the behavior
a bit like in KT-34027

See org.jetbrains.kotlin.resolve.calls.results.OverloadingConflictResolver#filterOutEquivalentCalls

Before 471134d we were comparing
"fun foo(x: String)" with "[substituted] fun foo(x: String)"
and areCallableDescriptorsEquivalent returned false for such case.
Thus, both overrides were left in the resulting set.

After 471134d, those two descriptors
becamed considered as equal thus having a possibility to remove any of them.

The problem is that "areCallableDescriptorsEquivalent" has kind of
unclear contract. Effectively it checks whether two descriptors match
to the same declaration

But straightforward fixing of this exact call-site (using original descriptors)
doesn't help: behavior might change in a very subtle way (see org.jetbrains.kotlin.spec.checkers.DiagnosticsTestSpecGenerated.NotLinked.Dfa.Pos#test72)

So, the main idea is changing the contract for areCallableDescriptorsEquivalent
only when project is HMPP one.

^KT-34027 In Progress
2019-09-30 20:09:42 +03:00
Mikhail Zarechenskiy 957af741cd [NI] Don't forget marker interface for type variables 2019-09-30 10:22:30 +03:00
Mikhail Zarechenskiy 1a50a3cbb1 [NI] Avoid computing few things for simple calls without type variables 2019-09-20 17:56:07 +03:00
Mikhail Zarechenskiy a83225218f [NI] Fix checks for infix/operator conventions 2019-09-20 17:56:06 +03:00
Mikhail Zarechenskiy 0431c21f9a [NI] Remove unneeded computation of possible types for return type
This call was needed at some point for smartcasts on qualified
 expressions but become obsolete (most likely after
 daa27016ca).

 Now `ComplexDataFlowBenchmark` has similar results for NI and OI
2019-09-18 00:19:21 +03:00
Mikhail Zarechenskiy f8449bf15a [NI] Clear partially resolved calls after resolve of top-level call
#KT-32433 Fixed
2019-09-09 11:04:17 +03:00
Mikhail Zarechenskiy dc25f7b7ac [NI] Minor, remove unneeded computation of constant evaluator 2019-09-09 11:04:16 +03:00
Dmitriy Novozhilov 3e44bc805f [FIR] Return error type from common super type if it present 2019-08-22 10:55:07 +03:00
Mikhail Zarechenskiy 1969ad6e9d [NI] Take into account use-site variance for constraint from LHS of CR
#KT-32851 Fixed
2019-08-15 13:01:38 +03:00
Mikhail Zarechenskiy 9f0991f0aa Minor, clean up type approximator a bit 2019-08-07 16:06:45 +03:00
Mikhail Zarechenskiy 04e57f712e [NI] Introduce feature for passing function references with defaults
Relates to KT-8834, we continue reducing differences between old and new
 inference. Note that as for `SamConversionPerArgument`, this feature
 is enabled in the compiler and not in the IDE to avoid breaking code
 for those users that already enabled new inference in the compiler
2019-08-07 15:58:36 +03:00
Mikhail Zarechenskiy 0219b86d06 [NI] Fix poor performance of recursive types approximation
#KT-32407 Fixed
2019-08-07 15:21:16 +03:00
Mikhail Zarechenskiy 5f76918c90 [NI] Use approximator as a component, don't recreate it during resolve 2019-08-07 15:21:15 +03:00
Dmitriy Novozhilov 8107d1515c [NI] Minor. Remove redundant code that was added for debugging 2019-08-01 14:37:49 +03:00
Dmitriy Novozhilov b6a7d21579 [NI] Fix extracting type variables for flexible types in in captured types
Bug was introduced in b99efb because of lack of tests.
All code in `AbstractTypeCheckerContextForConstraintSystem.extractTypeVariableForSubtype`
  related to IN projection looks suspicious and needs further investigation
2019-08-01 14:37:41 +03:00
Dmitriy Novozhilov 7245475196 [FIR] Add DeclaredUpperBoundConstraintPosition to Fir 2019-07-30 16:28:14 +03:00
Dmitriy Novozhilov 71ca1aa608 [Type system] Fix algorithm of folding recursive types
There was a problem when we get type from type projection even if
  it is a star projection what is meaningless. Now we try to fold argument
  only if it's not a star projection
2019-07-30 16:28:13 +03:00
Dmitriy Novozhilov 6215662e33 Replace usage of ClassicTCContext with abstract context in NewCSTCalculator 2019-07-30 16:28:13 +03:00
Dmitriy Novozhilov 9add14a2a1 [API Usage] Add refinement to ConstraintInjector (NI) 2019-07-30 12:41:38 +03:00
Denis Zharkov 53334c038f [API Usage] Use refinement in NI 2019-07-30 12:41:37 +03:00
Dmitry Savvinov c12f5f6055 [Core API] Introduce TypeConstructor.refine
This commit introduces TypeConstructor.refine method.

It's implementation can be roughly split in three parts:
- trivial implementations which just return 'this': mostly, it used for
typeConstructors which can not be refined at all (e.g.
IntegerValueTypeConstructor and other special cases of constructors)

- delegating implementations which call 'refine' recursively for
component typeConstructors -- obviously, they are used in composite
typeConstructors (like IntersectionTypeConstructor)

- finally, the most interesting one is in 'AbstractTypeConstructor'
which returns lightweight wrapper called 'ModuleViewTypeConstructor'.
The idea here is to propagate refinement to supertypes without eagerly
computing them all.

VERY IMPORTANT CAVEAT of TypeConstructor.refine is that call to this
method CAN NOT add new supertypes, so returned supertypes are not
entirely "valid". See the KDoc for TypeConstructor.refine for details
2019-07-30 12:41:37 +03:00
Dmitriy Novozhilov f026a98403 [Misc] Make NewKotlinTypeChecker non-static 2019-07-30 12:41:36 +03:00
Dmitriy Novozhilov b99efb9a2b [NI] Look for type variables in captured flexible types
#KT-32434 Fixed
2019-07-22 11:08:39 +03:00
Yan Zhulanow 54f78a2920 Debugger: Remove debugger-related hacks in resolution
Candidate ordering should be the same in ordinary Kotlin code and in evaluated expressions.
With the invention of 'foo_field' syntax, there is no need to do these nasty things any more.
2019-07-08 16:25:16 +09:00
Mikhail Zarechenskiy c2cf4aa2b5 [NI] Move ability to convert standalone SAM-argument under the feature
If new inference is enabled only for IDE analysis, then this feature
 will be disabled to reduce difference between new and old inference,
 but if new inference is enabled in the compiler, then this feature
 will be enabled too to preserve behavior of new inference for
 compilation

 #KT-32175 Fixed
 #KT-32143 Fixed
 #KT-32123 Fixed
 #KT-32230 Fixed
2019-07-01 12:53:33 +03:00
Mikhail Zarechenskiy c77f18fbe6 [NI] Support callable references on qualified types with generics
#KT-32154 Fixed
2019-06-26 00:23:12 +03:00
Mikhail Zarechenskiy a26cf86af7 [NI] Fix exception: callable reference is used with an unresolved LHS
#KT-32187 Fixed
2019-06-25 14:09:38 +03:00
Mikhail Zarechenskiy fe0282809e [NI] Skip fake call for descriptor from object in builder-inference
This call have interesting rules for resolution, see
 `KtQualifiedExpression.elementChain` function and it's usages:
 resolution results for such call can be omitted and be replaced with
 some other information, while diagnostics will be reported from
 builder-inference.

 To mitigate this problem, we'll just skip this call from builder-inference
 as such calls can't have type parameters anyway

 #KT-32094 Fixed
2019-06-21 11:56:09 +03:00
Mikhail Zarechenskiy f3e4c9cdb3 [NI] Don't avoid Nothing-like constraints if Nothing was in initial type
#KT-32081 Fixed
 #KT-32951 Fixed
2019-06-21 11:52:39 +03:00
Denis Zharkov bf0781d790 FIR: Implement fast path for classes subtyping 2019-06-20 15:42:42 +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 7df13c986e [NI] Coerce to Unit expression in last block with explicit Unit
#KT-32037 Fixed
2019-06-18 19:38:02 +03:00
Denis Zharkov 3c8ed21e59 Optimize ConstraintInjector::isMyTypeVariable
Do not look into the map for constructors that are not
type variables
2019-06-18 11:55:15 +03:00
Denis Zharkov fdebb38706 Disable slow assertions in type checker everywhere except for tests 2019-06-17 10:29:23 +03:00
Mikhail Zarechenskiy d9dca067f6 [NI] Propagate non-null info on supertypes for capturing from bounds
#KT-31941 Fixed
2019-06-13 00:57:51 +03:00
Alexander Udalov c67517cb2b JVM IR: use fast class reading mode in boxAgainstJava tests
annotationsViaActualTypeAliasFromBinary.kt is ignored because
ExpectActualRemover can't find actual for the expected constructor of
Anno now, because `ExpectedActualResolver.findActualForExpected`
incorrectly filters out actual declarations without any source file, and
Java classes loaded in the fast mode don't have any source files.

This will need to be fixed separately, probably by making
ExpectedActualResolver look for the actual class of an expected class
member first (with source file-based filtering), and then
unconditionally locating the corresponding member there
2019-06-11 15:26:07 +02:00
Dmitry Savvinov 32a102a99d Fix bug in ExpectedActualResolver
'getContributedDescriptors' isn't obliged to apply filters, inlcuding
kindFilter, and may return declarations of different kind, so we have to
call 'filterIsInstance' explicitly
2019-06-11 11:07:01 +03:00
Dmitry Savvinov 29beed9b21 [Expect/Actual] Support matching of expect/actual in hierarchical MPP 2019-06-10 13:34:27 +03:00
Mikhail Zarechenskiy e7064f5b77 [NI] Move creation of constraint system under callbacks
This will be needed in the next commit to have access to constraint
 system that is used for old inference
2019-06-07 18:37:18 +03:00
Mikhail Zarechenskiy 4ddd9f081b [NI] Consider explicitly specified type argument as an input type
#KT-31860 Fixed
2019-06-07 12:31:42 +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
Simon Ogorodnik 88a9349f32 Use intersection of star projection type-param bounds instead of type 2019-05-30 09:52:02 +03:00
Dmitriy Novozhilov e574106799 [NI] Support @OnlyInputTypes annotation. #KT-29307 fixed 2019-05-29 10:54:41 +03:00
Dmitriy Novozhilov 139497bafb [NI] Add checking @NotNull parameters for candidates 2019-05-29 10:53:07 +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 f702417655 [NI] Relax rules for call completion: require at least one constraint
It's enough to have at least one good constraint.

 Note that the whole algorithm can be a bit more general:
 we could check also Out<T>, In<T> and verify that T has good only
 lower constraint or upper constraint, but there are questions for
 types like Inv<Out<T>>, where T should have lower and upper constraints

 #KT-31514 Fixed
2019-05-29 02:14:00 +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
Mikhail Zarechenskiy 86a95e1a7b Revert "[NI] Add checking @NotNull parameters for candidates"
This reverts commit 910177ab17.
2019-05-29 01:31:27 +03:00