Skip to content

[Query] Control Flow

github-actions[bot] edited this page Oct 3, 2026 · 1 revision

Generated from 'wiki-query.ts' on 2026-09-10, 07:04:46 UTC (v2.15.8), do not edit directly.

Control-Flow Query [overview]

Provides the control-flow of the program.
This query is requested with the type control-flow.

This control-flow query provides you access to the control flow graph.

In other words, if you have a script simply reading: if(TRUE) 1 else 2, the following query returns the CFG:

[ { "type": "control-flow" } ]

(This can be shortened to @control-flow when used with the REPL command :query).

Show Results

Results (prettified and summarized):

Query: control-flow (2ms)
   ╰ CFG: https://mermaid.live/view#base64:eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgbjAoW1wiYFJMb2dpY2FsICgwKVxuKipUUlVFKipgXCJdKVxuICAgIG4xW1wiYFJOdW1iZXIgKDEpXG4qKjEqKmBcIl1cbiAgICBuNVtcImBSSWZUaGVuRWxzZSAoNSlcbioqaWYoVFJVRSkgMSBlbHNlIDIqKmBcIl1cbiAgICBuMCAtLT58XCJmbG93cyB0b1wifCBuMVxuICAgIG4xIC0tPnxcImZsb3dzIHRvXCJ8IG41XG4gICAgc3R5bGUgbjAgc3Ryb2tlOmN5YW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyAgICBzdHlsZSBuNSBzdHJva2U6Z3JlZW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyIsIm1lcm1haWQiOnsiYXV0b1N5bmMiOnRydWV9fQ==\

Show Detailed Results as Json

The analysis ran (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "control-flow": {
    ".meta": {},
    "controlFlow": {
      "graph": {"roots":[0,1,5],"vtxInfos":[[0,[2,0]],[1,[1,1]],[5,[1,5]]],"bbChildren":[],"edgeInfos":[[0,[[1,0]]],[1,[[5,0]]]],"mayHaveBasicBlocks":false},
      "entryPoints": [0],
      "exitPoints": [5],
      "returns": [],
      "breaks": [],
      "nexts": []
    }
  },
  ".meta": {}
}

You can also overwrite the simplification passes to tune the perspective. for example, if you want to have basic blocks:

[
  {
    "type": "control-flow",
    "config": {
      "simplificationPasses": [
        "unique-cf-sets",
        "to-basic-blocks"
      ]
    }
  }
]
Show Results

Results (prettified and summarized):

Query: control-flow (1ms)
   ╰ CFG: https://mermaid.live/view#base64:eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgc3ViZ3JhcGggbmJiLTAgW0Jsb2NrIGJiLTBdXG4gICAgICAgIGRpcmVjdGlvbiBURFxuICAgIG4wKFtcImBSTG9naWNhbCAoMClcbioqVFJVRSoqYFwiXSlcbiAgICBuMVtcImBSTnVtYmVyICgxKVxuKioxKipgXCJdXG4gICAgbjAgLS0+IG4xXG4gICAgbjVbXCJgUklmVGhlbkVsc2UgKDUpXG4qKmlmKFRSVUUpIDEgZWxzZSAyKipgXCJdXG4gICAgbjEgLS0+IG41XG4gICAgZW5kXG4gICAgc3R5bGUgbmJiLTAgc3Ryb2tlOmN5YW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyAgICBzdHlsZSBuYmItMCBzdHJva2U6Z3JlZW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyIsIm1lcm1haWQiOnsiYXV0b1N5bmMiOnRydWV9fQ==\

Show Detailed Results as Json

The analysis ran (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "control-flow": {
    ".meta": {},
    "controlFlow": {
      "returns": [],
      "entryPoints": ["bb-0"],
      "exitPoints": ["bb-0"],
      "breaks": [],
      "nexts": [],
      "graph": {
        "roots": ["bb-0"],
        "vtxInfos": [["bb-0",[3,"bb-0",[[2,0],[1,1],[1,5]]]]],
        "bbChildren": [[0,"bb-0"],[1,"bb-0"],[5,"bb-0"]],
        "edgeInfos": [],
        "mayHaveBasicBlocks": true
      }
    }
  },
  ".meta": {}
}

this produces:

flowchart LR
    subgraph nbb-0 [Block bb-0]
        direction LR
    n0(["`RLogical (0)
**TRUE**`"])
    n1["`RNumber (1)
**1**`"]
    n0 --> n1
    n5["`RIfThenElse (5)
**if(TRUE) 1 else 2**`"]
    n1 --> n5
    end
    style nbb-0 stroke:cyan,stroke-width:6.5px;    style nbb-0 stroke:green,stroke-width:6.5px;
Loading

(The analysis ran (including the dataflow analysis, normalization, and parsing with the r-shell engine) within the generation environment. We used the following simplifications: unique-cf-sets, to-basic-blocks . )

If, on the other hand, you want to prune dead code edges:

[
  {
    "type": "control-flow",
    "config": {
      "simplificationPasses": [
        "unique-cf-sets",
        "analyze-dead-code"
      ]
    }
  }
]
Show Results

Results (prettified and summarized):

Query: control-flow (1ms)
   ╰ CFG: https://mermaid.live/view#base64:eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgbjAoW1wiYFJMb2dpY2FsICgwKVxuKipUUlVFKipgXCJdKVxuICAgIG4xW1wiYFJOdW1iZXIgKDEpXG4qKjEqKmBcIl1cbiAgICBuNVtcImBSSWZUaGVuRWxzZSAoNSlcbioqaWYoVFJVRSkgMSBlbHNlIDIqKmBcIl1cbiAgICBuMCAtLT58XCJmbG93cyB0b1wifCBuMVxuICAgIG4xIC0tPnxcImZsb3dzIHRvXCJ8IG41XG4gICAgc3R5bGUgbjAgc3Ryb2tlOmN5YW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyAgICBzdHlsZSBuNSBzdHJva2U6Z3JlZW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyIsIm1lcm1haWQiOnsiYXV0b1N5bmMiOnRydWV9fQ==\

Show Detailed Results as Json

The analysis ran (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "control-flow": {
    ".meta": {},
    "controlFlow": {
      "returns": [],
      "entryPoints": [0],
      "exitPoints": [5],
      "breaks": [],
      "nexts": [],
      "graph": {"roots":[0,1,5],"vtxInfos":[[0,[2,0]],[1,[1,1]],[5,[1,5]]],"bbChildren":[],"edgeInfos":[[0,[[1,0]]],[1,[[5,0]]]],"mayHaveBasicBlocks":false}
    }
  },
  ".meta": {}
}

this produces:

flowchart LR
    n0(["`RLogical (0)
**TRUE**`"])
    n1["`RNumber (1)
**1**`"]
    n5["`RIfThenElse (5)
**if(TRUE) 1 else 2**`"]
    n0 -->|"flows to"| n1
    n1 -->|"flows to"| n5
    style n0 stroke:cyan,stroke-width:6.5px;    style n5 stroke:green,stroke-width:6.5px;
Loading

(The analysis ran (including the dataflow analysis, normalization, and parsing with the r-shell engine) within the generation environment. We used the following simplifications: unique-cf-sets, analyze-dead-code . )

Or, completely remove dead code:

[
  {
    "type": "control-flow",
    "config": {
      "simplificationPasses": [
        "unique-cf-sets",
        "analyze-dead-code",
        "remove-dead-code"
      ]
    }
  }
]
Show Results

Results (prettified and summarized):

Query: control-flow (2ms)
   ╰ CFG: https://mermaid.live/view#base64:eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgbjAoW1wiYFJMb2dpY2FsICgwKVxuKipUUlVFKipgXCJdKVxuICAgIG4xW1wiYFJOdW1iZXIgKDEpXG4qKjEqKmBcIl1cbiAgICBuNVtcImBSSWZUaGVuRWxzZSAoNSlcbioqaWYoVFJVRSkgMSBlbHNlIDIqKmBcIl1cbiAgICBuMCAtLT58XCJmbG93cyB0b1wifCBuMVxuICAgIG4xIC0tPnxcImZsb3dzIHRvXCJ8IG41XG4gICAgc3R5bGUgbjAgc3Ryb2tlOmN5YW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyAgICBzdHlsZSBuNSBzdHJva2U6Z3JlZW4sc3Ryb2tlLXdpZHRoOjYuNXB4OyIsIm1lcm1haWQiOnsiYXV0b1N5bmMiOnRydWV9fQ==\

Show Detailed Results as Json

The analysis ran (including parsing and normalization and the query) within the generation environment.

In general, the JSON contains the Ids of the nodes in question as they are present in the normalized AST or the dataflow graph of flowR. Please consult the Interface wiki page for more information on how to get those.

{
  "control-flow": {
    ".meta": {},
    "controlFlow": {
      "returns": [],
      "entryPoints": [0],
      "exitPoints": [5],
      "breaks": [],
      "nexts": [],
      "graph": {"roots":[0,1,5],"vtxInfos":[[0,[2,0]],[1,[1,1]],[5,[1,5]]],"bbChildren":[],"edgeInfos":[[0,[[1,0]]],[1,[[5,0]]]],"mayHaveBasicBlocks":false}
    }
  },
  ".meta": {}
}

this produces:

flowchart LR
    n0(["`RLogical (0)
**TRUE**`"])
    n1["`RNumber (1)
**1**`"]
    n5["`RIfThenElse (5)
**if(TRUE) 1 else 2**`"]
    n0 -->|"flows to"| n1
    n1 -->|"flows to"| n5
    style n0 stroke:cyan,stroke-width:6.5px;    style n5 stroke:green,stroke-width:6.5px;
Loading

(The analysis ran (including the dataflow analysis, normalization, and parsing with the r-shell engine) within the generation environment. We used the following simplifications: unique-cf-sets, analyze-dead-code, remove-dead-code . )

Implementation Details

Responsible for the execution of the Control-Flow Query query is executeControlFlowQuery in ./src/queries/catalog/control-flow-query/control-flow-query-executor.ts.

Clone this wiki locally