== println == fun println(obj: Any?) {} --------------------- L0: 1 INIT: in: {} out: {} v(obj: Any?) INIT: in: {} out: {} magic[FAKE_INITIALIZER](obj: Any?) -> INIT: in: {} out: {} w(obj|) INIT: in: {} out: {} 2 mark({}) INIT: in: {} out: {} read (Unit) L1: 1 error: sink: USE: in: {} out: {} ===================== == Demo0 == class Demo0 { private val some = object { fun foo() { println(state) // Ok } } private var state: Boolean = true } --------------------- L0: 1 INIT: in: {} out: {} v(private val some = object { fun foo() { println(state) // Ok } }) INIT: in: {} out: {} mark(object { fun foo() { println(state) // Ok } }) INIT: in: {} out: {} jmp?(L2) d(fun foo() { println(state) // Ok }) USE: in: {state=READ} out: {state=READ} L2 [after local declaration]: r(object { fun foo() { println(state) // Ok } }) -> w(some|) INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == foo == fun foo() { println(state) // Ok } --------------------- L3: 2 INIT: in: {} out: {} 3 mark({ println(state) // Ok }) magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {} out: {state=READ} mark(println(state)) call(println(state), println|) -> L4: 2 error: sink: USE: in: {} out: {} ===================== == Demo1 == class Demo1 { private val some = object { fun foo() { if (state) state = true println(state) // must be initialized } } private var state: Boolean = true } --------------------- L0: 1 INIT: in: {} out: {} v(private val some = object { fun foo() { if (state) state = true println(state) // must be initialized } }) INIT: in: {} out: {} mark(object { fun foo() { if (state) state = true println(state) // must be initialized } }) INIT: in: {} out: {} jmp?(L2) d(fun foo() { if (state) state = true println(state) // must be initialized }) INIT: in: {state=I} out: {state=I} USE: in: {state=READ} out: {state=READ} L2 [after local declaration]: r(object { fun foo() { if (state) state = true println(state) // must be initialized } }) -> INIT: in: {} out: {} w(some|) INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == foo == fun foo() { if (state) state = true println(state) // must be initialized } --------------------- L3: 2 INIT: in: {} out: {} 3 mark({ if (state) state = true println(state) // must be initialized }) mark(if (state) state = true) magic[IMPLICIT_RECEIVER](state) -> r(state|) -> jf(L5|) USE: in: {state=READ} out: {state=READ} magic[IMPLICIT_RECEIVER](state) -> r(true) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=WRITTEN_AFTER_READ} w(state|, ) INIT: in: {} out: {state=I} USE: in: {state=READ} out: {state=WRITTEN_AFTER_READ} jmp(L6) INIT: in: {state=I} out: {state=I} L5 [else branch]: read (Unit) INIT: in: {} out: {} L6 ['if' expression result]: merge(if (state) state = true|!) -> INIT: in: {state=I} out: {state=I} magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {} out: {state=READ} mark(println(state)) call(println(state), println|) -> L4: 2 error: INIT: in: {} out: {} sink: INIT: in: {state=I} out: {state=I} USE: in: {} out: {} ===================== == Demo1A == class Demo1A { fun foo() { if (state) state = true println(state) // Ok } private var state: Boolean = true } --------------------- L0: 1 INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == foo == fun foo() { if (state) state = true println(state) // Ok } --------------------- L0: 1 INIT: in: {} out: {} 2 mark({ if (state) state = true println(state) // Ok }) mark(if (state) state = true) magic[IMPLICIT_RECEIVER](state) -> r(state|) -> jf(L2|) magic[IMPLICIT_RECEIVER](state) -> r(true) -> w(state|, ) jmp(L3) L2 [else branch]: read (Unit) L3 ['if' expression result]: merge(if (state) state = true|!) -> magic[IMPLICIT_RECEIVER](state) -> r(state|) -> mark(println(state)) call(println(state), println|) -> L1: 1 error: sink: USE: in: {} out: {} ===================== == Demo2 == class Demo2 { private val some = object { fun foo() { if (state) state = true else state = false println(state) // OK } } private var state: Boolean = true } --------------------- L0: 1 INIT: in: {} out: {} v(private val some = object { fun foo() { if (state) state = true else state = false println(state) // OK } }) INIT: in: {} out: {} mark(object { fun foo() { if (state) state = true else state = false println(state) // OK } }) INIT: in: {} out: {} jmp?(L2) d(fun foo() { if (state) state = true else state = false println(state) // OK }) INIT: in: {state=I} out: {state=I} USE: in: {state=READ} out: {state=READ} L2 [after local declaration]: r(object { fun foo() { if (state) state = true else state = false println(state) // OK } }) -> INIT: in: {} out: {} w(some|) INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == foo == fun foo() { if (state) state = true else state = false println(state) // OK } --------------------- L3: 2 INIT: in: {} out: {} 3 mark({ if (state) state = true else state = false println(state) // OK }) mark(if (state) state = true else state = false) magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=READ} jf(L5|) magic[IMPLICIT_RECEIVER](state) -> r(true) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=WRITTEN_AFTER_READ} w(state|, ) INIT: in: {} out: {state=I} USE: in: {state=READ} out: {state=WRITTEN_AFTER_READ} jmp(L6) INIT: in: {state=I} out: {state=I} USE: in: {state=READ} out: {state=READ} L5 [else branch]: magic[IMPLICIT_RECEIVER](state) -> INIT: in: {} out: {} r(false) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=WRITTEN_AFTER_READ} w(state|, ) INIT: in: {} out: {state=I} USE: in: {state=READ} out: {state=WRITTEN_AFTER_READ} L6 ['if' expression result]: merge(if (state) state = true else state = false|!, !) -> INIT: in: {state=I} out: {state=I} magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {} out: {state=READ} mark(println(state)) call(println(state), println|) -> L4: 2 error: INIT: in: {} out: {} sink: INIT: in: {state=I} out: {state=I} USE: in: {} out: {} ===================== == Demo3 == class Demo3 { private val some = run { if (state) state = true println(state) // OK } private var state: Boolean = true } --------------------- L0: 1 INIT: in: {} out: {} v(private val some = run { if (state) state = true println(state) // OK }) INIT: in: {} out: {} magic[IMPLICIT_RECEIVER](run { if (state) state = true println(state) // OK }) -> INIT: in: {} out: {} mark({ if (state) state = true println(state) // OK }) jmp?(L2) d({ if (state) state = true println(state) // OK }) USE: in: {state=READ} out: {state=READ} L2 [after local declaration]: r({ if (state) state = true println(state) // OK }) -> mark(run { if (state) state = true println(state) // OK }) call(run { if (state) state = true println(state) // OK }, run|, ) -> w(some|) INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == anonymous_0 == { if (state) state = true println(state) // OK } --------------------- L3: 2 INIT: in: {} out: {} 3 mark(if (state) state = true println(state) // OK) mark(if (state) state = true) magic[IMPLICIT_RECEIVER](state) -> r(state|) -> jf(L5|) USE: in: {state=READ} out: {state=READ} magic[IMPLICIT_RECEIVER](state) -> r(true) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=WRITTEN_AFTER_READ} w(state|, ) USE: in: {state=READ} out: {state=WRITTEN_AFTER_READ} jmp(L6) L5 [else branch]: read (Unit) L6 ['if' expression result]: merge(if (state) state = true|!) -> magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {} out: {state=READ} mark(println(state)) call(println(state), println|) -> L4: 2 error: sink: USE: in: {} out: {} ===================== == run == fun T.run(f: T.() -> R) = f() --------------------- L0: 1 INIT: in: {} out: {} v(f: T.() -> R) INIT: in: {} out: {} magic[FAKE_INITIALIZER](f: T.() -> R) -> INIT: in: {} out: {} w(f|) INIT: in: {} out: {} r(f) -> INIT: in: {} out: {} magic[IMPLICIT_RECEIVER](f()) -> mark(f()) call(f(), invoke|, ) -> ret(*|) L1 L1: error: sink: USE: in: {} out: {} ===================== == exec == fun exec(f: () -> T): T = f() --------------------- L0: 1 INIT: in: {} out: {} v(f: () -> T) INIT: in: {} out: {} magic[FAKE_INITIALIZER](f: () -> T) -> INIT: in: {} out: {} w(f|) INIT: in: {} out: {} r(f) -> INIT: in: {} out: {} mark(f()) call(f(), invoke|) -> ret(*|) L1 L1: error: sink: USE: in: {} out: {} ===================== == Demo4 == class Demo4 { private val some = exec { if (state) state = true println(state) // must be initialized } private var state: Boolean = true } --------------------- L0: 1 INIT: in: {} out: {} v(private val some = exec { if (state) state = true println(state) // must be initialized }) INIT: in: {} out: {} mark({ if (state) state = true println(state) // must be initialized }) INIT: in: {} out: {} jmp?(L2) d({ if (state) state = true println(state) // must be initialized }) INIT: in: {state=I} out: {state=I} USE: in: {state=READ} out: {state=READ} L2 [after local declaration]: r({ if (state) state = true println(state) // must be initialized }) -> INIT: in: {} out: {} mark(exec { if (state) state = true println(state) // must be initialized }) call(exec { if (state) state = true println(state) // must be initialized }, exec|) -> w(some|) INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == anonymous_1 == { if (state) state = true println(state) // must be initialized } --------------------- L3: 2 INIT: in: {} out: {} 3 mark(if (state) state = true println(state) // must be initialized) mark(if (state) state = true) magic[IMPLICIT_RECEIVER](state) -> r(state|) -> jf(L5|) USE: in: {state=READ} out: {state=READ} magic[IMPLICIT_RECEIVER](state) -> r(true) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=WRITTEN_AFTER_READ} w(state|, ) INIT: in: {} out: {state=I} USE: in: {state=READ} out: {state=WRITTEN_AFTER_READ} jmp(L6) INIT: in: {state=I} out: {state=I} L5 [else branch]: read (Unit) INIT: in: {} out: {} L6 ['if' expression result]: merge(if (state) state = true|!) -> INIT: in: {state=I} out: {state=I} magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {} out: {state=READ} mark(println(state)) call(println(state), println|) -> L4: 2 error: INIT: in: {} out: {} sink: INIT: in: {state=I} out: {state=I} USE: in: {} out: {} ===================== == Demo5 == class Demo5 { private var state: Boolean = true private val some = object { fun foo() { if (state) state = true println(state) // OK } } } --------------------- L0: 1 INIT: in: {} out: {} v(private var state: Boolean = true) INIT: in: {} out: {state=D} r(true) -> INIT: in: {state=D} out: {state=D} w(state|) INIT: in: {state=D} out: {state=ID} v(private val some = object { fun foo() { if (state) state = true println(state) // OK } }) INIT: in: {state=ID} out: {state=ID} mark(object { fun foo() { if (state) state = true println(state) // OK } }) INIT: in: {state=ID} out: {state=ID} jmp?(L2) d(fun foo() { if (state) state = true println(state) // OK }) INIT: in: {state=I} out: {state=I} USE: in: {state=READ} out: {state=READ} L2 [after local declaration]: r(object { fun foo() { if (state) state = true println(state) // OK } }) -> INIT: in: {state=ID} out: {state=ID} w(some|) INIT: in: {state=ID} out: {state=ID} L1: INIT: in: {state=ID} out: {state=ID} error: INIT: in: {} out: {} sink: INIT: in: {state=I?} out: {state=I?} USE: in: {} out: {} ===================== == foo == fun foo() { if (state) state = true println(state) // OK } --------------------- L3: 2 INIT: in: {state=ID} out: {state=ID} 3 mark({ if (state) state = true println(state) // OK }) mark(if (state) state = true) magic[IMPLICIT_RECEIVER](state) -> r(state|) -> jf(L5|) USE: in: {state=READ} out: {state=READ} magic[IMPLICIT_RECEIVER](state) -> r(true) -> USE: in: {state=WRITTEN_AFTER_READ} out: {state=WRITTEN_AFTER_READ} w(state|, ) USE: in: {state=READ} out: {state=WRITTEN_AFTER_READ} jmp(L6) L5 [else branch]: read (Unit) L6 ['if' expression result]: merge(if (state) state = true|!) -> magic[IMPLICIT_RECEIVER](state) -> USE: in: {state=READ} out: {state=READ} r(state|) -> USE: in: {} out: {state=READ} mark(println(state)) call(println(state), println|) -> L4: 2 error: INIT: in: {} out: {} sink: INIT: in: {state=I} out: {state=I} USE: in: {} out: {} =====================