@@ -570,7 +570,14 @@ module Flow<InputSig Input> implements OutputSig<Input> {
570570 pragma [ only_bind_out ] ( closureExprGetCallable ( ce ) )
571571 }
572572
573- /** Holds if we need an additional read of `v` TODO */
573+ /**
574+ * Holds if we need an additional read of `v` in the `i`th node of `bb` in
575+ * order to synchronize the value stored on `closure`.
576+ * `topScope` is true if the read is in the defining callable of `v`.
577+ *
578+ * Side-effects of potentially calling `closure` at this point will be
579+ * observed in a similarly synthesized post-update node for this read of `v`.
580+ */
574581 private predicate synthRead (
575582 CapturedVariable v , BasicBlock bb , int i , boolean topScope , Expr closure
576583 ) {
@@ -582,6 +589,10 @@ module Flow<InputSig Input> implements OutputSig<Input> {
582589 if v .getCallable ( ) != bb .getEnclosingCallable ( ) then topScope = false else topScope = true
583590 }
584591
592+ /**
593+ * Holds if there is an access of a captured variable inside a closure in the
594+ * `i`th node of `bb`, such that we need to synthesize a `this.` qualifier.
595+ */
585596 private predicate synthThisQualifier ( BasicBlock bb , int i ) {
586597 synthRead ( _, bb , i , false , _) or
587598 captureRead ( _, bb , i , false , _) or
@@ -592,6 +603,11 @@ module Flow<InputSig Input> implements OutputSig<Input> {
592603 TVariable ( CapturedVariable v ) or
593604 TThis ( Callable c ) { captureAccess ( _, c ) }
594605
606+ /**
607+ * A storage location for a captured variable in a specific callable. This is
608+ * either the variable itself (in its defining scope) or an instance variable
609+ * `this` (in a capturing scope).
610+ */
595611 private class CaptureContainer extends TCaptureContainer {
596612 string toString ( ) {
597613 exists ( CapturedVariable v | this = TVariable ( v ) and result = v .toString ( ) )
@@ -600,6 +616,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
600616 }
601617 }
602618
619+ /** Holds if `cc` needs a definition at the entry of its callable scope. */
603620 private predicate entryDef ( CaptureContainer cc , BasicBlock bb , int i ) {
604621 exists ( Callable c |
605622 entryBlock ( bb ) and
@@ -681,6 +698,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
681698 TMallocNode ( ClosureExpr ce ) { hasConstructorCapture ( ce , _) }
682699
683700 class ClosureNode extends TClosureNode {
701+ /** Gets a textual representation of this node. */
684702 string toString ( ) {
685703 exists ( CapturedVariable v | this = TSynthRead ( v , _, _, _) and result = v .toString ( ) )
686704 or
@@ -705,6 +723,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
705723 result = "malloc" and this = TMallocNode ( _)
706724 }
707725
726+ /** Gets the location of this node. */
708727 Location getLocation ( ) {
709728 exists ( CapturedVariable v , BasicBlock bb , int i , Expr closure |
710729 this = TSynthRead ( v , bb , i , _) and
@@ -893,6 +912,7 @@ module Flow<InputSig Input> implements OutputSig<Input> {
893912 |
894913 post = true
895914 or
915+ // for a constructor call the regulare ExprNode is the post-update for the MallocNode
896916 post = false and hasConstructorCapture ( closure , v )
897917 )
898918 or
0 commit comments