Commit Graph

192 Commits

Author SHA1 Message Date
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 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 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
Dmitrii Gridin be7d282974 [FIR] introduce FirReceiverParameter
^KT-54417
2022-11-17 09:50:09 +00:00
Ilya Chernikov c02923c5b5 [minor] FIR resolution for dynamics - use more appropriate prio 2022-11-12 14:34:08 +01:00
Anna Kozlova 9f470e2a4d [LL API] return FirErrorProperty for top level destructuring declaration
KTIJ-23552
2022-11-11 17:39:54 +01:00
Ilya Kirillov 725ae1fc65 [Analysis API] separate non-class error types from class error types and add information about type qualifiers
it's needed for type printing in renderer
2022-11-11 11:59:55 +01:00
pyos 20871dd555 FIR DFA: update assignment indices when joining flows 2022-11-03 13:33:11 +00:00
pyos 8e40566520 Minor: make a function that intersects N maps shorter 2022-11-03 13:33:10 +00:00
pyos 639a454d6c FIR DFA: when joining flows, clear reassigned vars with no statements
For example:

    val c = C("...")
    val x = c.x // alias to variable for c.x, which depends on c
    if (x == null) return
    // now c.x has type Any
    c = C(null)
    // c has been reassigned => info for c.x is no longer valid;
    // c itself has never had any statements made about it, but
    // we must still call removeAllAboutVariable to clear the
    // dependents
2022-11-03 13:33:10 +00:00
pyos 0781cd12d4 FIR DFA: copy logic statements to aliases before removing variables
^KT-54744 Fixed
2022-11-03 13:33:09 +00:00
Dmitriy Novozhilov 7af43176ce [FIR] Add optin on API of updating type of receiver values. KT-54708 2022-11-03 08:30:09 +00:00
Dmitriy Novozhilov be3f8e7eb0 [FIR] Remove redundant opt-ins to ExperimentalStdlibApi in FIR modules 2022-10-19 11:09:33 +00:00
Dmitriy Novozhilov fa9f0bcf84 [FIR] Ignore CFA-only edges in DFA even if they are dead
^KT-53920 Fixed
2022-10-19 11:09:33 +00:00
vladislav.grechko 817afcd4af KT-MR-7307 review fixes 2022-10-13 15:19:10 +00:00
Dmitriy Novozhilov ee21c966e1 [FIR] Get rid of all usages of safeAs in FIR modules 2022-10-06 06:57:06 +00:00
Nikolay Lunyak dccb7faf2e [FIR] KT-53479: Paraphrase INSTANCE_ACCESS_BEFORE_SUPER_CALL 2022-09-20 09:51:20 +00:00
Nikolay Lunyak 3d9c77efa8 [FIR] Add DNN checks
Merge-request: KT-MR-7000
Merged-by: Nikolay Lunyak <lunyak.kolya@mail.ru>
2022-09-01 14:25:07 +00:00
Nikita Bobko 8f79e833a8 Drop all redundant kotlin-reflect, kotlin-reflect-api dependencies
Review: https://jetbrains.team/p/kt/reviews/6753

All redundant I managed to find, of course.

Why: I'm going to process all reflect dependencies in the next commits.
Cleanup reflect dependency before processing.

They are redundant because:
1. if `compileOnly` then compilation didn't break after dropping the
   dependency
2. if `test*` then tests didn't break after dropping the dependency.
3. `analysis/analysis-api-fir/analysis-api-fir-generator/build.gradle.kts`
   `compiler/fir/checkers/checkers-component-generator/build.gradle.kts`
   Drop `implementation(project(":kotlin-reflect-api"))` because the
   module already depends on
   `implementation(project(":kotlin-reflect"))`
4. `compiler/daemon/daemon-client/build.gradle.kts`. Drop `runtimeOnly`
   because after dropping `compileOnly` compilation didn't break (so
   `runtimeOnly` looks suspicious). Less safe than 1-3
2022-08-22 15:42:57 +02:00
Dmitriy Novozhilov bb38690273 [FIR] Introduce FirAssignExpressionAltererExtension
This extension can be used to override resolution of assign statements
  with custom statement
2022-08-19 07:44:09 +00:00
Simon Ogorodnik 513af2dfbc FIR. Refactor smart-cast representation in FIR tree
Make smart-casts non-transparent expression without delegation
to underlying FirQualifiedAccessExpression, as children delegation in
fir tree has unclear semantics
Remove two different kinds of tree nodes for smart-casts
2022-08-15 21:46:11 +00:00
Ilya Kirillov 0748f28efe [FIR] rename ensureResolve -> lazyResolveToPhase as it better describes function semantics 2022-08-10 22:49:18 +02:00
Mikhail Glukhikh 3e58c54da9 Add docs to CandidateApplicability, remove DSL_SCOPE_VIOLATION 2022-07-27 15:29:48 +00:00
Mikhail Glukhikh 010d5b76e5 Temporary fix for K2/JS tests 2022-07-27 15:29:46 +00:00
Mikhail Glukhikh 0611f3b8e7 CandidateApplicability: add K1/K2 prefixes when applicable 2022-07-27 15:29:44 +00:00
Mikhail Glukhikh 8e9e8302f7 CandidateApplicability: merge INAPPLICABLE_MODIFIER into CONVENTION_ERROR 2022-07-27 15:29:43 +00:00
Mikhail Glukhikh 32a73968de Stop tower resolve in K2 in more similar manner with K1 2022-07-27 15:29:41 +00:00
Mikhail Glukhikh 801426d0e6 Simplify creation of FirRenderer 2022-07-14 09:38:44 +00:00
Mikhail Glukhikh 3fe35e6997 Extract separate FirCallArgumentsRenderer 2022-07-14 09:38:39 +00:00
Mikhail Glukhikh 7c27e6f843 FirRenderer: partially get rid of RenderMode 2022-07-14 09:38:37 +00:00
Mikhail Glukhikh 089044e5b0 FirRenderer: get rid of direct Visitor usages 2022-07-14 09:38:34 +00:00
Mikhail Glukhikh 998ed8849f FirRenderer: drop effectively unused renderLambdaBodies parameter 2022-07-14 09:38:34 +00:00
Mikhail Glukhikh a82baf87cb FIR renderer: extract separate ConeTypeRenderer 2022-07-14 09:38:33 +00:00
Mikhail Glukhikh f64a7d3ff9 FirRenderer: extract separate printer & visitor 2022-07-14 09:38:32 +00:00
Mikhail Glukhikh 38d6f3d548 Move FirRenderer to separate package 2022-07-14 09:38:31 +00:00
Mikhail Glukhikh 065e852199 FIR: support more precise diagnostics about parameter names
#KT-52762 Fixed
2022-06-20 11:28:55 +00:00