Commit Graph

96319 Commits

Author SHA1 Message Date
Nikolay Krasko c414b4b29a Update CODEOWNERS for scripts directory 2022-11-22 20:29:22 +00:00
Nikolay Krasko 4c16d7597a Instructions for building 1.7.20 release 2022-11-22 20:29:21 +00:00
Nikolay Krasko 41d16b1376 Scripts for building Kotlin repository 2022-11-22 20:29:20 +00:00
Nikolay Lunyak 4b3dc008f0 [FIR] KT-54260: Fix the compiler crash
AllOpen plugin makes the properties all-open, but the annotation class
is left closed, because allopen for k2 literally checks
`classKind == CLASS`.

Since the properties are open, a
`NON_FINAL_MEMBER_IN_FINAL_CLASS` diagnostic is reported for them. It's
positioning strategy seeks for the explicit `open` modifier which is
not present.

The added test should not crash the compiler.

^KT-54260 Fixed
2022-11-22 20:25:38 +00:00
Jinseong Jeon c79d65536b Gracefully handle erroneous super type during local type approximation
^KTIJ-23528 Fixed
2022-11-22 20:16:40 +01:00
Ilya Kirillov f775778efa [Analysis API FIR] fix containing declaration for value parameter
now it should also work for non-source declarations
2022-11-22 18:25:30 +01:00
Ilya Kirillov 7781ad67d4 [FIR] introduce FirValueParameter.containingFunctionSymbol
^KT-55034 fixed
2022-11-22 18:25:30 +01:00
Ilya Kirillov c8e3103af9 [FIR] do not create FirParameter for catch parameter
use FirProperty instead

^KT-55034
2022-11-22 18:25:30 +01:00
Ilya Kirillov 9671e20f1f [FIR] do not create FirParameter during creation of for loop variable
^KT-55034
2022-11-22 18:25:30 +01:00
Dmitriy Novozhilov eb8ce449e3 [FIR] Don't lose flexible types during capturing from expression 2022-11-22 15:46:22 +00:00
Dmitriy Novozhilov 06e88b559a [FIR] Consider ConeConstraintSystemHasContradiction as a good reason for DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE error 2022-11-22 15:46:21 +00:00
Dmitriy Novozhilov 9b7b517f43 [FIR] Properly resolve declarations inside contract calls on CONTRACT phase 2022-11-22 15:46:21 +00:00
Dmitriy Novozhilov 01c6c7dc59 [FIR] Properly approximate return type of callable declarations
- approximate intersection types in all non-local declarations
- approximate local types in non-private non-local declarations
2022-11-22 15:46:20 +00:00
Dmitriy Novozhilov 0f70635fcb [FIR] Don't run FirFunctionReturnTypeMismatchChecker on only return statements of single expression bodies
This is needed not only as optimization, but also for cases, when
  inferred type of function may differ from type of single expression.
  Such situation may occur after next commit, which adds approximation
  of return type of all declarations:
```
interface A
interface B
interface C : A, B
interface D : A, B

class Inv<T>(val x: T, val y: T)

fun foo(c: C, d: D) /* : Inv<Any> */ = Inv(c, d) /*: Inv<A & B> */
// Inv<A & B> /<: Inv<Any>
// but there should be no error
```
2022-11-22 15:46:20 +00:00
Dmitriy Novozhilov 991d8c18aa [FIR] Fix incorrect inference of return type of anonymous functions
Also remove incorrect subtype check checkers

Test unsafeVarianceInAliasedFunctionalType.kt started to fail because
  of KT-54894. This bug existed before, changes from this commit just
  unhided it (previously it was hidden because incorrect subtype check
  in `isSubtypeForTypeMismatch` which is used by FirFunctionReturnTypeMismatchChecker
2022-11-22 15:46:19 +00:00
Dmitriy Novozhilov 1b42298025 [FIR] Implement IMPLICIT_NOTHING_*_TYPE diagnostics 2022-11-22 15:46:19 +00:00
Dmitriy Novozhilov 0e84bf2053 [FIR] Don't report ARGUMENT_TYPE_MISMATCH on error types 2022-11-22 15:46:19 +00:00
Dmitriy Novozhilov 32f6b71525 [FE] Add ability to configure PublicDeclaration type approximation configuration
This configuration allows to choose what to do with local and anonymous types
2022-11-22 15:46:18 +00:00
Dmitriy Novozhilov 82c39187f6 [FIR] Refactor: rename function 2022-11-22 15:46:18 +00:00
Dmitriy Novozhilov 07567d6748 [FIR] Always fix type variables with UNKNOWN direction 2022-11-22 15:46:18 +00:00
Dmitriy Novozhilov 1b27d60307 [FIR] Support @OnlyInputTypes annotation
^KT-54807 Fixed
2022-11-22 15:46:17 +00:00
pyos 5cc08fb314 FIR DFA: check for reassignments of LHS when handling ?..
`x?.y != null` does not imply that `x != null` if e.g. an argument to
`y` has reassigned `x` in the meantime.

The same is true for `x == y` and `functionWithContract(x, y)`, but
those are somewhat harder to implement since there is no easy way to
find the last node of a certain argument.

^KT-55096
2022-11-22 15:44:38 +00:00
pyos ae1048f8a9 FIR DFA: try to group mutations to persistent data structures
Thinking of monomorphizing `Flow` (= `PersistentFlow`) and instead
adding a completely separate `MutableFlow` version; then `joinFlow`
would produce a mutable one, data flow analysis would add some
statements, convert to a persistent `Flow` and proceed to the next
node.
2022-11-22 15:44:38 +00:00
pyos ea1caf0955 FIR DFA: do not generate nodes (and flows) for contracts on calls
The code was already duplicated between FirDataFlowAnalyzer and
FirReturnsImpliesAnalyzer, so might as well use the latter to slightly
speed up the former.
2022-11-22 15:44:37 +00:00
pyos 67a6785f63 FIR DFA: move eq/notEq null-to-type translation to LogicSystem
This makes the `returns() implies` checker slightly cleaner, and also
fixes the case that I've missed where in RHS of `x ?:` type of `x` was
not set to `Nothing?`.
2022-11-22 15:44:37 +00:00
pyos 564eca58dd FIR DFA: don't update receivers' types if flow is unchanged 2022-11-22 15:44:36 +00:00
pyos 49f8de50c3 FIR DFA: reduce the number of redundant statements created
If a variable does not yet exist, then it should only be created if it
is a real variable and the implication or statement we're about to add
is about its type or nullability (which is also about the type).
Otherwise, the statement/implication will have no effect because there
are currently no implications referencing that variable, and if it's
synthetic then there will never be because we won't visit it again.

Hopefully this reduces the performance impact of flow forks.
2022-11-22 15:44:36 +00:00
pyos ae31275f73 FIR DFA: unwrap transparent expressions in more places 2022-11-22 15:44:35 +00:00
pyos 2e9cccd809 FIR DFA: add a utility function for intersecting with original type 2022-11-22 15:44:35 +00:00
pyos 5b08c300f4 FIR DFA: don't assume != true/false => == false/true
This also fixes some returnsNotNull contracts because the old code added
an implication that `== true` => `!= null` then promptly removed any
statement that this could've affected if the argument was a synthetic
variable.

^KT-26612 tag fixed-in-k2
2022-11-22 15:44:34 +00:00
pyos 98f52f13ef FIR DFA: remove approved and impossible statements from flows 2022-11-22 15:44:34 +00:00
pyos 5796f0eb07 FIR DFA: clean up LogicSystem API
Receivers have nothing to do with it.
2022-11-22 15:44:33 +00:00
pyos 1506c493c8 FIR DFA: do not re-approve statements from LHS of and/or
If the right-hand side is evaluated at all, then in its flow those
statements were already approved. Re-approving them erases the effect of
reassignments.

^KT-28369 tag fixed-in-k2
2022-11-22 15:44:32 +00:00
pyos edaca59d83 FIR DFA: fork flow everywhere
In theory, forking persistent flows should be cheap because of object
reuse, so the proposal here is to start from scratch and prove
redundancy of forks on a case-by-case basis. Something something better
safe than sorry.

^KT-28333 tag fixed-in-k2
^KT-28489 tag fixed-in-k2
2022-11-22 15:44:32 +00:00
pyos 757921e63e FIR DFA: remove exactNotType
Literally not used for anything anymore. What a waste of CPU time.

...and safeCallBreakInsideDoWhile is broken again. Oh well.
2022-11-22 15:44:31 +00:00
pyos 6ee6d019ee FIR DFA: align return-implies checker closer to smartcasts 2022-11-22 15:44:31 +00:00
pyos 512deeb07b FIR DFA: avoid inverting type statements
By necessity, type statements underapproximate. Therefore, inverting
doesn't always produce an equal result. It's best to propagate negations
inwards to preserve precision as much as possible.
2022-11-22 15:44:30 +00:00
pyos 39f6b50836 FIR DFA: slightly simplify {and,or}ForTypeStatements
And use them less in boolean expression analysis. This uncovers a fun
new case that doesn't work:

    interface I { val x: String }
    class C(override val x: String) : I
    class D(override val x: String) : I

    fun foo(x: Any?) {
      if (x is D || (x as C).x != "") {
        println(x.x.length) // actually OK (x is D || x is C => x is I)
      }
    }
2022-11-22 15:44:30 +00:00
pyos ac0137f45f FIR DFA: do not remove statements about LHS of !!
Value equality statements about the result also propagate to left-hand
side, so these statements can still be useful.
2022-11-22 15:44:29 +00:00
pyos 1ff968eca2 FIR DFA: extract approveStatementsInsideFlow(variable notEq null)
I'm not sure how this fixes a test. Magic!
2022-11-22 15:44:29 +00:00
pyos 623dfdd5a3 FIR DFA: generate more correct implications on as/as?
^KT-54851 Fixed
2022-11-22 15:44:28 +00:00
pyos 6a2d74e211 FIR DFA: generate type implications on all null comparisons 2022-11-22 15:44:28 +00:00
pyos bc9b358c9f FIR DFA: bring into compliance with De Morgan's laws
I don't even know if this affects any real code, but it did uncover
some deeper issues, like the fact that `!is` did not add any statements
when `true`.
2022-11-22 15:44:27 +00:00
pyos 3436535e7a FIR DFA: deprioritize branches with no reassignments in flow unions
callBothLambdas({ x = "..." }, { x is Int })
  // the assignment always executes, so x is String | (String & Int);
  // the latter is always a subtype of the former so it can be ignored
2022-11-22 15:44:27 +00:00
pyos fd609416c6 Minor: FIR DFA: do not merge type statements for aliases
The result is the same as for whatever is being aliased
2022-11-22 15:44:26 +00:00
pyos 2ae06a8d46 FIR DFA: when removing a variable, move type statements about dependents
val c = C("...")
  val d = c
  if (c.x == null) return
  c.x.length // c.x has type String
  d.x.length // d.x -> c.x through d -> c
  c = C(null) // remove alias d -> c
  d.x.length // info from c.x moved to d.x

^KT-54824 Fixed
2022-11-22 15:44:26 +00:00
pyos 3cea2d7243 FIR DFA: assert that type statements are not attached to aliases 2022-11-22 15:44:25 +00:00
pyos ceb1607057 FIR DFA: when breaking aliasing, keep the rest of the group together
var a = ...
  var b = a
  var c = a
  a = ...
  // b and c still aliased
2022-11-22 15:44:25 +00:00
pyos 7c8e9ac316 FIR DFA: remove RealVariableAndType 2022-11-22 15:44:24 +00:00
pyos 33363ba1fc Add more variable aliasing tests 2022-11-22 15:44:23 +00:00