Commit Graph

400 Commits

Author SHA1 Message Date
Steven Schäfer 3f4c5c8d53 Resolve type aliases when looking for default arguments to actual methods.
Change-Id: I059093c1af32fcd7a2de36c25160c352d6f03a3c
2019-03-14 14:59:34 +01:00
Mikhail Zarechenskiy 1594c1fc6b [NI] Don't consider Nothing-constraint as proper to complete call
Follow-up of 9b3e17f0. There we decided to complete call if a type
 variable from a return type has proper lower constraints, now we refine
 this rule wrt `Nothing`-like constraints to avoid inferring type variables
 to Nothing, which is quite useless

 #KT-30370 Fixed
2019-03-11 19:14:29 +03:00
Dmitriy Novozhilov 9b50d31169 NI. Fix StackOverFlow in type approximation. #KT-30021 Fixed 2019-03-07 16:24:53 +03:00
Mikhail Zarechenskiy 7c357c0ec0 [NI] Complete calls during one inference session only once
The problem is that delegated properties resolve two calls together:
 `getValue`/`setValue` with a common receiver, which can contain
 callable references. For each completion new anonymous descriptor
 was created and caused "rewrite at slice" exceptions later.
 Now there is a little hack to check that during one inference session
 we don't complete one call more than one time.

 More correct fix would be to explicitly specify common receiver for
 inference session but it requires quite big refactoring, which will
 be done later with a whole refactoring of the common solver

 #KT-30250 Fixed
2019-03-05 13:33:22 +03:00
Simon Ogorodnik 4882627712 Make type-system KotlinType-independent
- Port NewKotlinTypeChecker.equalTypes
- Decouple new-type transform from isSubtypeOf
- Port isSubtypeForSameConstructor
- Port checkSubtypeForSpecialCases
- Port isSubTypeOf without internals
- Port anySupertype
- Port isSubtypeForSameConstructor, findCorrespondingSupertypes
- Port isSubtypeOfForSingleClassifierType
- Port NullabilityChecker
- Reorder checks for performance
2019-03-04 17:27:45 +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
Mikhail Zarechenskiy 92b40ea9d5 [NI] Refactor adding expected type constraint
Add comments, make computation needed for expected type more clear
2019-03-04 11:29:38 +03:00
Dmitriy Novozhilov 7072b9d179 Fix order of fixing type variables for callable references. KT-25433 Fixed 2019-03-01 14:50:33 +03:00
Dmitry Savvinov 50d1c013fc Force-resolve body in contract computation under lock
Even though acquire/release pattern guarantees memory visibility across
threads, it doesn't prevents concurrent access to critical section (i.e.
to force-resolve of the corresponding body).

This can lead to multiple resolution passes over one and the same PSI in
IDE, which, in turn, leads to 'rewrite at slice'-exceptions. See
KT-30030 for case description and details.

^KT-30030 Fixed
2019-02-25 11:10:16 +03:00
Dmitriy Novozhilov 3e147af3c0 KT-27565 fix 2019-02-22 10:15:16 +03:00
Dmitriy Novozhilov d58ee133a2 Fix type constraints of empty lambda (KT-28654 fix) 2019-02-21 12:04:23 +03:00
Dmitriy Novozhilov dfb379d999 Expand Effect System with receiver values (#KT-28672)
Add some classes to hierarchy of `ESValue`:
- `ESReceiver` -- representation of receiver
  of lambda function
- `ESDataFlow` and `ESDataFlowReceiver` -- little refactoring of entities
  that holds information for DFA (description in comments in code).

Also add kdoc to classes of `ESValue` hierarchy
2019-01-31 17:25:13 +03:00
Dmitriy Novozhilov ba71bbde6a Extract InvocationKind class into separate file 2019-01-31 17:25:13 +03:00
Dmitry Savvinov 4694a7963b Allow actuals with more permissive visibility
Allow non-virtual expects to have actuals with more permissive
visibility.

^KT-19664 Fixed
2019-01-31 12:29:27 +03:00
Mikhael Bogdanov a122cba862 Switch Kotlin project to jvm-target 1.8
#KT-29405
2019-01-31 07:43:05 +01:00
Mikhail Zarechenskiy 738271aba6 Refactoring: rename CheckArguments -> CheckArgumentsInParenthesis 2019-01-30 14:56:33 +03:00
Mikhail Zarechenskiy 147d7844bc [NI] Dont' add trivial constraints with Nothing from incorporation
#KT-24490 Fixed
 #KT-26816 Fixed
2019-01-30 13:48:33 +03:00
Mikhail Zarechenskiy 662e2287cc [NI] Discriminate resulting type Nothing(?) at fixation stage 2019-01-30 13:48:28 +03:00
Mikhail Zarechenskiy 0b0e335cdd [NI] Discriminate constraints with Nothing(?) lower bounds 2019-01-30 13:44:48 +03:00
Alexander Udalov 6cd3d9f19a Do not use DefaultBuiltIns.Instance in ESConstant
Add ESComponents and ESConstants to encapsulate usages of built-ins in
different functors and operators
2019-01-28 15:18:52 +01:00
Alexander Udalov 9516d6e89b Do not use DefaultBuiltIns in contracts
Default built-ins represent built-ins loaded from the compiler jar via
class loader, and they may not be equivalent to the built-ins present in
the standard library that is used in compilation dependencies, in case
the compiler and stdlib versions do not match. Use built-ins from the
given module instead.

This commit deals with more-or-less obvious usages of DefaultBuiltIns;
next commits refactor the ESConstant values and related code to support
injected built-ins
2019-01-28 15:18:52 +01:00
Alexander Udalov 7561502956 Refactor AndFunctor/OrFunction: do not use strictPartition
Instead use a filter with a simple check. This seems to be slightly
better both for readability (`strictPartition` gave an impression that
two its parameters were related in some way, but they were totally
independent) and for performance (do not create unnecessary objects,
instead decompose the existing objects and check their structure)
2019-01-28 15:18:52 +01:00
Alexander Udalov 07931451b1 Add utilities to check if ESValue is boolean/wildcard constant 2019-01-28 15:18:51 +01:00
Alexander Udalov cf19fa832c Add utility to check if effect is ESReturns
Somewhat simplify related code in AbstractBinaryFunctor and
AbstractUnaryFunctor
2019-01-28 15:18:51 +01:00
Sergey Rostov f35185b261 Build: remove explicit dependencies to org.jetbrains.annotations 2019-01-28 13:43:08 +03:00
Dmitriy Novozhilov 2c74796b0b Fix detecting upper bounds of generics of typealiases constructors in NI 2019-01-24 10:53:58 +03:00
Dmitriy Novozhilov 7f48897e21 Add NON_VARARG_SPREAD and SPREAD_OF_NULLABLE diagnostics to new inference 2019-01-24 10:53:58 +03:00
Dmitry Savvinov e483f83666 Make 'is'-operator more stupid
Consider following expression: 'call() is Foo'. Suppose that we know
something about the 'call()', e.g. 'returns(foo) -> <condition>'

Previously, we've tried to re-use knowledge about 'call()', constructing
some smart clause, like 'returns(true) -> foo is Foo && <condition>'.

The conceptual error here is that *we can't* argue that <condition>
holds. Imagine that 'call()' actually has unspecified 'returns(foo2) ->
<!condition>', and 'foo2 is Foo' also holds. Then we would get
'returns(true) -> foo2 is Foo && <condition>' <=> 'returns(true) ->
<condition>' for the whole call, which is not correct.

More concrete example would be something like:
'if (!x.isNullOrEmpty() is Boolean)'

^KT-27241 Fixed
2019-01-17 12:47:27 +03:00
Dmitry Savvinov a4d1a8f60a Get rid of FUNCTOR slice, use lazy value in ContractDecription instead
Functor is an imperative representation of function's contract (contrary
to ContractDescription, which is a declarative one). ContractDescription
is convenient when we deal with sources of contracts declarations
(binaries, source), while Functors are convenient for analyzing code
with contracts.

It means that we have to convert ContractDescription into Functor when
we start working with contracts. This computation isn't trivial, and
Functor and ContractDescription are in 1-1 correspondence, so we would
like to cache Functor for each ContractDescription somewhere.

We used to do this in binding trace, in slice FUNCTOR.

Now, it turns out that this approach causes "Rewrite at slice"
exception, see KT-28847. We won't go into details of why that happens
here, you can see the issue comments for details (but be prepared for the
very long and nitty-gritty story)

This commit removes the problematic slice and introduces another
approach, where Functor is attached to the ContractDescription, computed
lazily and cached here.

^KT-28847 Fixed
2019-01-14 11:11:03 +03:00
Sergey Rostov 883970fadb Add explicit dependencies to nullable annotations 2018-12-26 09:07:06 +03:00
Mikhail Zarechenskiy 84222afe2f Fix exception when expected type is subtype of a function type
#KT-28984 Fixed
 #EA-132850 Fixed
2018-12-24 19:41:51 +03:00
Mikhail Zarechenskiy 1d69f35f27 Revert "[NI] Take into account captured types for type depth computation"
This reverts commit 383c2d1bff.

 It seems this commit causes problems with bootstraping, so it'll be
 investigated and refined later
2018-12-12 17:41:30 +03:00
Mikhail Zarechenskiy e8a8318ead [NI] Fix input/output types for callable reference atom
Input and output types are crucial for type variable fixation order and
 analysis of postponed arguments (callable references, lambdas).

 Specifically, if there is non-fixed type variable inside input types of
 a callable reference, then we'll postpone resolution for such callable
 reference.

 Initial example with the expected type `KMutableProperty1<*, F>` caused
 problems because input types were computed incorrectly (while there
 aren't input types here)

 #KT-25431 Fixed
2018-12-11 11:33:29 +03:00
Mikhail Zarechenskiy 383c2d1bff [NI] Take into account captured types for type depth computation
It's needed to estimate the count of steps for type approximation algorithm.
 After the estimated count of steps, we consider such type recursive and this
 algorithm returns some default value

 #KT-28598 Fixed
2018-12-11 11:29:55 +03:00
Cuihtlauac ALVARADO ece745966b Remove CandidateWithBoundDispatchReceiverImpl
Interface CandidateWithBoundDispatchReceiver had a unique
implementation, which was private.

Turned interface CandidateWithBoundDispatchReceiver into a
class. Removed CandidateWithBoundDispatchReceiverImpl. Removed
string "Impl" suffix at constructor call sites.
2018-12-04 19:01:48 +03:00
Mikhail Zarechenskiy 6e27d7a2a5 [NI] Refactor common supertype calculator
Make filtration phases more explicit, get rid of `filterNot`
2018-11-29 14:08:04 +03:00
Mikhail Zarechenskiy 7a9fb3ca26 [NI] Fix coercion to Unit for explicitly specified type argument
#KT-25424 Fixed
2018-11-22 18:10:39 +03:00
Mikhail Zarechenskiy c6712ff861 [NI] Correctly compute definitely not null type for intersection one
{ T : Any? & Foo & Bar? }!! -> { T!! & Foo & Bar }

 Also, fix bug with loosing non-representative number type.
 For example, for type { Byte & SomeType } we lost type `Byte` because
 `getDefaultPrimitiveNumberType` returns null for it

 Fixes #KT-28334 for NI
2018-11-22 18:10:37 +03:00
Denis Zharkov 9cb8a35275 Minor. Pull user-data related things to CallableDescriptor
Currently, we assume user data for all non-FunctionDescriptor
declarations is empty
2018-09-12 09:49:25 +03:00
Mikhail Glukhikh ad4da3d761 Code cleanup: convert flatMap { it } into flatten() 2018-09-07 16:32:18 +03:00
Alexander Udalov 34c033bcaf Take ReceiverParameterDescriptor in FunctionDescriptorImpl.initialize
Instead of just KotlinType. This will allow to pass annotations on the
receiver at call sites
2018-08-27 23:37:04 +02:00
Cuihtlauac ALVARADO 813d7ff84a Remove useless parameter
It seems a candidate is added either when requiresExtensionReceiver is true and
receiver is not null or when requiresExtensionReceiver is false and receiver is null.
Consequently, f appears useless.
2018-08-24 18:48:03 +03:00
Cuihtlauac ALVARADO eb7d77ebd9 Accept renaming and formating requests
* Rename "resolve" into "resolveCandidates"
* Use multi-line formatting for formal parameters
* Move ")" down one line at call sites
2018-08-24 18:48:03 +03:00
Cuihtlauac ALVARADO bf08755969 Factor duplicated code.
Move SimpleScopeTowerProcessor from TowerResolver into ScopeTowerProcessors.

Lift code duplicated in functions:

  * ExplicitReceiverScopeTowerProcessor.simpleProcess()
  * QualifierScopeTowerProcessor.simpleProcess()
  * NoExplicitReceiverScopeTowerProcessor.simpleProcess()

into AbstractSimpleScopeTowerProcessor. Turn it into a function and call it
in the various context. Incidentally, now useless functions resolveAsMember()
and resolveAsExtension() are  removed.
2018-08-24 18:48:03 +03:00
Mikhail Zarechenskiy 1a511166cc Discriminate unsigned types in overload resolution
#KT-24717 Fixed
 Relates to #KT-25996 and #KT-25997
2018-08-09 09:49:17 +03:00
Dmitry Savvinov 76c651421b Deprecate visibility of static members inherited from Java
Now they are not visible by short name through companion objects, just
like classifiers in KT-21515

^KT-25333 In progress
2018-07-19 13:32:38 +03:00
Ilmir Usmanov eea95441c5 Add diagnostics tests. Forbid callable reference to coroutineContext
#KT-16908: Fixed
2018-07-05 15:08:42 +03:00
Mikhail Zarechenskiy 8148bdc4d0 Support inline classes in MPP resolver/checker model 2018-06-08 19:13:39 +03:00
Mikhail Zarechenskiy 9891f562cc [NI] Make subtyping algorithm more robust to error types
During subtyping/incorporation we transform types (e.g. changing nullability,
 form of the type) and, basically, we're doing this to some FIXPOINT.
 It's important that we use `KotlinType.hashCode()` to compare types, but
 for error types hashCode is a hashCode of its supertype and, for example,
 `makeNullableAsSpecified` method recreate type every time. So, we continue
 to generate new constraints and we'll never stop incorporation algorithm
2018-06-07 15:45:53 +03:00
Mikhail Zarechenskiy 04c13aeae8 [NI] Fix exception on capturing type with inner typealiased typed 2018-06-05 14:05:50 +03:00