Commit Graph

294 Commits

Author SHA1 Message Date
Mikhail Zarechenskiy c6d8b39b4f [NI] Prioritize type variables related to output type for fixation 2017-12-19 15:11:04 +03:00
Mikhail Zarechenskiy d47130eff8 [NI] Don't check type for constants too early to avoid mismatch 2017-12-07 14:18:20 +03:00
Mikhail Zarechenskiy 6c27a49114 [NI] Use effective variance for equal approximated type
It's totally safe from the point of type system and reduces extra `out` projections that can add problems with subtyping
2017-12-07 14:18:17 +03:00
Dmitry Savvinov 874267b79d Report cyclic scopes properly
This commit introduces proper handling of recursion in scopes, which
could occur when some of companion object supertypes are members of
that companion owner:

```
class Container {
  open class Base
  companion object : Base()
}
```

To resolve `Base`, we have to build member scope for `Container`.
In the member scope of `Container`, we see all classifiers from
companion and his supertypes
So, we have to resolve companion objects supertype, which happens to be
`Base` again - therefore, we encounter recursion here.

Previously, we created `ThrowingLexicalScope` for such recursive calls,
but didn't checked for loop explicitly, which lead to a wide variety of
bugs (see https://jetbrains.quip.com/dc5aABhZoaQY and KT-10532).

To report such cyclic declarations properly, we first change
`ThrowingLexicalScope` to `ErrorLexicalScope` -- the main difference is
that latter doesn't throws ISE when someone tries to resolve type in it,
allowing us to report error instead of crashing with exception.

Then, we add additional fake edge in supertypes graph (from
host-class to companion object) which allows us to piggyback on existing
supertypes loops detection mechanism, and report such cycles for user.
2017-12-07 14:14:08 +03:00
Dmitry Savvinov aaee401240 [NI] Minor renaming
Use words 'returnArgument' instead of 'resultArgument' when talking
about values, which can be possibly returned from lambda.

Correct 'addSubsystemForArgument' -> 'addSubsystemFromArgument'
2017-12-07 12:49:56 +03:00
Dmitry Savvinov 30a51af931 [NI] Minor: rename typo KotlinCallDiagnistics.kt -> KotlinCallDiagnostics.kt 2017-12-07 12:49:56 +03:00
Dmitry Savvinov 957bbe291d [NI] Don't approximate error types
Previously, we did approximation of error types to Any?/Nothing in some
contexts (e.g. non-local declarations).

There are several reasons why it is not desired:
- OI doesn't approximate ErrorType
- This behaviour is inconsistent with ourselves (i.e. sometimes we *do*
  infer errortype for top-level declaration)
- It causes different digressions from OI in reported diagnostics

This commit turns off error type approximation. It causes large testdata
shift, which is deliberately split into several parts and commited in a
separate commits.
2017-12-07 12:49:56 +03:00
Dmitry Savvinov eadd1355c2 [NI] Add ErrorType constraint
Previously, constraint wasn't added if bound was ErrorType. That could
cause TypeVariable to be inferred to Any?/Nothing instead of ErrorType,
which could influence other parts of analysis (in particular, inferring
Nothing instead of ErrorType can cause bogus UNREACHABLE_CODE diagnostics)

Because of that fix, intersection type can be added to CS as supertype,
which provokes AssertionError. This commit also relaxes this assertion,
as it seems that it's valid that supertype is an intersection type.
2017-12-07 12:49:56 +03:00
Dmitry Savvinov 9f63818bd3 [NI] Introduce INAPPLICABLE_ARGUMENTS_MAPPING_ERROR for some NI diagnostics 2017-12-07 12:49:56 +03:00
Dmitry Savvinov e2d65adc7e [NI] Fix KotlinResolutionCandidate.isSuccessfull
Check if ConstrainSystem has any contradiction in 'isSuccessful'.
Otherwise we may erroneously think that there are some successful
candidates in 'TowerResolver.SuccessfullResultCollector.pushCandidates()'
and clear other unsuccessful ones (while they actually may have higher
applicability).
2017-12-07 12:49:56 +03:00
Mikhail Zarechenskiy 1d736f59b6 [NI] Refine nullability for CST of types with undefined nullability 2017-12-06 18:36:20 +03:00
Mikhail Zarechenskiy b9d390449c [NI] Refactor constraints transformations, update comments 2017-12-06 18:36:19 +03:00
Mikhail Zarechenskiy 351c592c83 [NI] Drop hack that was used before DefinitelyNotNull types 2017-12-06 18:36:17 +03:00
Mikhail Zarechenskiy 64f0688b71 [NI] Introduce DefinitelyNotNullType as type for T!! or {T & Any} 2017-12-06 18:36:11 +03:00
Mikhail Zarechenskiy 8e0171d475 [NI] Don't loose platform types on simplifying lower constraints 2017-12-06 18:08:52 +03:00
Mikhail Zarechenskiy bee7ed1431 [NI] Fix mapping of type arguments to parameters for inner classes 2017-11-22 10:22:41 +03:00
Mikhail Zarechenskiy e526a87d54 [NI] Make model more robust: remove diagnostics from resolution atoms
Currently there are two major phases in NI that report diagnostics: resolution parts and completion. They connected in method `KotlinCallCompleter.runCompletion` and previously diagnostics were collected in several places, from resolution atoms, partly from constraint system and partly from `CallResolutionResult`, some of them were lost.

 To mitigate this problem, now diagnostics are not bind to the intermediate candidate, only to the result resolution candidate (overloaded or usual one). And all diagnostics are now collected in method `runCompletion`
2017-11-22 10:22:39 +03:00
Mikhail Zarechenskiy 20e1caaab1 [NI] Use refined expected type by smartcasts in CS 2017-11-17 15:04:20 +03:00
Mikhail Zarechenskiy 66064345e9 [NI] Support fallback resolution for refined sams priority feature 2017-11-16 18:07:54 +03:00
Mikhail Zarechenskiy e42f07b031 [NI] Wait for proper constraints to fix type for callable reference
If expected type is a type variable, then we'll wait for proper constraints, but previously we resolved callable reference as it didn't have expected type at all, because type variable isn't a functional type

 Consider the following example:

 fun foo(i: Int) {}
 fun foo(s: String) {}
 fun <T> id(x: T): T = x

 fun test() {
     val x1: (Int) -> Unit = id(id(::foo))
 }

 Here we shouldn't resolve callable reference until we get constraint from expected type of `x1`
2017-11-16 18:07:51 +03:00
Alexander Udalov 7ace303add Fix ambiguity on callable reference for expect members
Expect members should always lose in resolution to non-expect members,
be it simple calls or callable references. Note that there should be
exactly one actual member for each expect member in correct code, so
both ways to check for expect vs non-expect are correct: either before
signature comparison, or after.

 #KT-20903 Fixed
2017-11-15 11:02:29 +01:00
Mikhail Zarechenskiy fbe274ff09 [NI] Use less specific type for captured type approximation
This is needed to be more compatible with the old NI
2017-11-14 14:40:47 +03:00
Mikhail Zarechenskiy f3ef961be6 [NI] Report error about non-spread parameter from arguments mapper 2017-11-14 13:55:48 +03:00
Mikhail Zarechenskiy 2aa8ceb005 [NI] Fix state for named arguments in arguments to parameters mapper 2017-11-14 13:54:51 +03:00
Mikhail Zarechenskiy 519e5c33d8 [NI] Support assigning single array elements in named form to varargs 2017-11-13 16:47:05 +03:00
Mikhail Zarechenskiy fe2499b47f [NI] Approximate flexible types with enhancement as usual ones
This is temporary and should be fixed later
2017-11-13 16:35:24 +03:00
Mikhail Zarechenskiy f51f7a0fe4 [NI] Report diagnostic about receiver as super expression 2017-11-13 16:33:08 +03:00
Mikhail Zarechenskiy 1d6e9c244b [NI] Report diagnostic about spread argument to non vararg parameter 2017-11-13 16:32:58 +03:00
Mikhail Zarechenskiy 73b4e24d54 Introduce language feature for NI, remove old setting 2017-11-13 16:23:04 +03:00
Alexander Udalov 02981038f3 Split core into descriptors, descriptors.jvm, deserialization, descriptors.runtime 2017-11-10 18:58:31 +01:00
Dmitry Savvinov d20c770a25 Effects: add test on (de)serialization of contracts
- Add ContractDescriptorRenderer
- Add option to dump function contracts in DescriptorRendererOptions
- Add parsing of LANGUAGE_VERSION directive in AbstractLoadJava
- Add tests on serialization-deserializaton identity of contracts

==========
Introduction of EffectSystem: 13/18
2017-10-12 11:55:26 +03:00
Alexander Udalov a4f378d04d Decrease resolution priority of declarations from kotlin-stdlib-jre7/8
In order to allow "overload resolution ambiguity" when both
kotlin-stdlib-jre7/8 and kotlin-stdlib-jdk7/8 are in the dependencies
2017-10-11 19:23:38 +03:00
Dmitry Savvinov 175d23155e Effects: add (de)serialization of contracts in metadata
- Introduce new definitions in descriptors.proto
- Add new corresponding values in Flags.java
- Introduce ContractSerializer and ContractDeserializer, responsible for
for conversion ContractDescription <-> ProtoBuf.Contract
- Add dependency of 'serialization' module on 'resolution' so that it
could see contracts model.

Note that here we do a lot of seemingly unnecessary hoops, which in fact
necessary to respect existing module system (in particular, to be able
to extract ContractDescription declarations from 'descriptors' module to
make them invisible from reflection)

==========
Effect System introduction: 8/18
2017-10-11 13:34:54 +03:00
Dmitry Savvinov d2e582698e Effects: add interpreters of ContractDescription
Interpreters convert declarative representation of contracts
(ContractDescription) in internal representation convenient for usage
inside compiler (Computations, Effects, etc.)

==========
Effect System introduction: 3/18
2017-10-11 13:34:54 +03:00
Dmitry Savvinov afc15e9211 Effects: Add inner representation of contracts
Add model of contracts used by compiler during analysis. It should be
thought of as structure which used by the compiler to implement
semantics, expressed by the ContractDescription.

==========
Effect System introduction: 2/18
2017-10-11 13:34:54 +03:00
Dmitry Savvinov ba84bd3f19 Effects: Add declarations for description of contracts
Add ContractDescription structure which is used for declarative representation
of function's contract.

Also, add corresponding LanguageFeatures.

==========
This is the first commit from a series of 18 commits which gradually
introduce effect system into the compiler. All such commits will be
marked with appropriate comment and index in that series.

While each one of such commits separately shouldn't break compiler (i.e
you can checkout any of them and expect compiler to build and pass
tests successfully, e.g. for bissecting purposes), semantically they
all are one big feature and not entirely independent. Please bear that
in mind while working with/changing only some of them -- some strange
effects can happen.
2017-10-11 13:34:54 +03:00
Denis Zharkov 1c9b454d90 Rename KotlinTypeFactory::simpleType to simpleTypeWithNonTrivialMemberScope
To state it must be used only for limited number of cases
2017-10-10 18:27:00 +03:00
Mikhail Zarechenskiy f3344ec2b2 Treat expect classes as not having implicit default constructors
#KT-15522 Fixed
2017-10-05 00:10:42 +03:00
Denis Zharkov 0d5a2a7e18 Minor. Drop unused class ScopeLevelsAndSkippedForLookups 2017-09-28 14:01:30 +03:00
Denis Zharkov 5b01a32bd3 Extract val isNameForHidesMember 2017-09-28 14:01:30 +03:00
Denis Zharkov 1f23d610a6 Extract TowerResolver.Task::processImplicitReceiver 2017-09-28 14:01:30 +03:00
Denis Zharkov 6b97203979 Move all state from TowerResolver.Task::run to Task class
Also extract local functions from it and introduce
TowerData.ForLookupForNoExplicitReceiver class
2017-09-28 14:01:30 +03:00
Denis Zharkov c7fda42ccc Introduce TowerResolver.Task class
Its main purpose is code simplification: ImplicitScopeTower::run
contains a lot of local functions that are needed because of
lots of shared state

So, we're moving the state to the Task class instead

NB: This change doesn't change the code of `run`, it will be done
in further commits
2017-09-28 14:01:30 +03:00
Denis Zharkov b1387b2ae7 Make call resolution responsible for calling recordLookups
The idea is that all tower levels are partitioned into two groups:
- ones that may contain the target name or INVOKE; they're processed as usual
- ones that can't contain the name; they're simply skipped until
the end of resolution process when it's being passed to scope processors
to allow them record necessary lookups
2017-09-28 14:01:30 +03:00
Denis Zharkov 580a7e3e4d Drop location parameter from ResolutionScope::definitelyDoesNotContainName
definitelyDoesNotContainName is called too eagerly sometimes and it leads
to obviously redundant lookups

The idea is to put responsibility for calling recordLookup to resolution
itself
2017-09-28 14:01:30 +03:00
Denis Zharkov 37440c70e2 Optimize invoke processors
- Avoid creating of empty KnownResultProcessor for variables
- Do not consider definetely inapplicable tower data
2017-09-28 14:01:30 +03:00
Denis Zharkov 860951748f Filter out inapplicable member scopes in resolution 2017-09-28 14:01:30 +03:00
Denis Zharkov d0bf0f5fb3 Filter out inapplicable non-local levels for implicit receivers 2017-09-28 14:01:30 +03:00
Denis Zharkov 51d3969822 Do not run resolution processors for inapplicable statics 2017-09-28 14:01:30 +03:00
Denis Zharkov 3322ed6e04 Implement LazyImportResolver::definitelyDoesNotContainName 2017-09-28 14:01:30 +03:00