-
Notifications
You must be signed in to change notification settings - Fork 14
[Query] Static Slice
This document was generated from 'src/documentation/wiki-query.ts' on 2026-07-20, 17:48:26 UTC presenting an overview of flowR's query API (v2.12.3). Please do not edit this file/wiki page directly.
Static Slice Query [overview]
Slice the dataflow graph reducing the code to just the parts relevant for the given criteria (backward and forward).
This query is requested with the type static-slice.
Run in the REPL: :query @static-slice (<crit>;...)[fiIcB] <code | file://path>
To slice, flowR needs one thing from you: a variable or a list of variables (function calls are supported to, referring to the anonymous return of the call) that you want to slice the dataflow graph for (additionally, you have to tell flowR if you want to have a forward slice). Given this, the backward slice is essentially the subpart of the program that may influence the value of the variables you are interested in. To specify a variable of interest, you have to present flowR with a slicing criterion (or, respectively, an array of them).
To exemplify the capabilities, consider the following code:
x <- 1
y <- 2
z <- 3
xIf you are interested in the parts required for the use of x in the last line and z, you can use the following query:
[
{
"type": "static-slice",
"criteria": [
"3@z",
"4@x"
]
}
](This can be shortened to @static-slice (3@z;4@x) "x <- 1\ny <- 2\nz <- 3\nx" when used with the REPL command :query).
Results (prettified and summarized):
x <- 1
z <- 3
x
All queries together required ≈5 ms (1ms accuracy, total 5 ms)
Show Detailed Results as Json
The analysis required 5.4 ms (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.
{
"static-slice": {
".meta": {
"timing": 5
},
"results": {
"{\"type\":\"static-slice\",\"criteria\":[\"3@z\",\"4@x\"]}": {
"slice": {
"timesHitThreshold": 0,
"result": [
6,
9,
0,
1,
2,
"built-in:<-",
7,
8
],
"slicedFor": [
6,
9
],
".meta": {
"timing": 5
}
},
"reconstruct": {
"code": "x <- 1\nz <- 3\nx",
"linesWithAutoSelected": 0,
".meta": {
"timing": 0
}
}
}
}
},
".meta": {
"timing": 5
}
}In general, you may be uninterested in seeing the reconstructed version and want to save some computation time, for this,
you can use the noReconstruction flag.
No Reconstruction Example
[
{
"type": "static-slice",
"criteria": [
"4@x"
],
"noReconstruction": true
}
]Results (prettified and summarized):
Query: static-slice (4 ms)
╰ Slice for {4@x} no reconstruction
╰ Id List: {9, 0, 1, 2, built-in:<-, }
All queries together required ≈4 ms (1ms accuracy, total 5 ms)
Show Detailed Results as Json
The analysis required 4.9 ms (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.
{
"static-slice": {
".meta": {
"timing": 4
},
"results": {
"{\"type\":\"static-slice\",\"criteria\":[\"4@x\"],\"noReconstruction\":true}": {
"slice": {
"timesHitThreshold": 0,
"result": [
9,
0,
1,
2,
"built-in:<-"
],
"slicedFor": [
9
],
".meta": {
"timing": 4
}
}
}
}
},
".meta": {
"timing": 4
}
}Likewise, if you want the forward slice for the first use of x, you can do it like this:
[
{
"type": "static-slice",
"criteria": [
"1@x"
],
"direction": "forward"
}
](This can be shortened to @static-slice (1@x)f "x <- 1\ny <- 2\nz <- 3\nx" when used with the REPL command :query).
Results (prettified and summarized):
x <- 1
x
All queries together required ≈6 ms (1ms accuracy, total 7 ms)
Show Detailed Results as Json
The analysis required 6.6 ms (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.
{
"static-slice": {
".meta": {
"timing": 6
},
"results": {
"{\"type\":\"static-slice\",\"criteria\":[\"1@x\"],\"direction\":\"forward\"}": {
"slice": {
"timesHitThreshold": 0,
"result": [
0,
2,
9
],
"slicedFor": [
0
],
".meta": {
"timing": 6
}
},
"reconstruct": {
"code": "x <- 1\nx",
"linesWithAutoSelected": 0,
".meta": {
"timing": 0
}
}
}
}
},
".meta": {
"timing": 6
}
}If your program pulls in other files with source(...), the inlineSources flag splices the reconstruction
of each resolvable sourced file into the place of its source() call, so the slice becomes a single
self-contained R text (cyclic or unresolvable source() calls are kept verbatim and reported via
reconstruct.inlineWarnings). With the :query REPL command you append an i to the
criteria (and may combine it with the forward f as fi), for example (with a faked library.R providing greeting):
[
{
"type": "static-slice",
"criteria": [
"2@print"
],
"inlineSources": true
}
](This can be shortened to @static-slice (2@print)i "source("library.R")\nprint(greeting)" when used with the REPL command :query).
Results (prettified and summarized):
greeting <- "hello"
print(greeting)
All queries together required ≈193 ms (1ms accuracy, total 195 ms)
Show Detailed Results as Json
The analysis required 195.4 ms (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.
{
"static-slice": {
".meta": {
"timing": 193
},
"results": {
"{\"type\":\"static-slice\",\"criteria\":[\"2@print\"],\"inlineSources\":true}": {
"slice": {
"timesHitThreshold": 0,
"result": [
7,
5,
"built-in:print",
"library.R:1:1-0",
3,
"library.R:1:1-1",
"library.R:1:1-2",
"built-in:<-",
1,
"built-in:source"
],
"slicedFor": [
7
],
".meta": {
"timing": 193
}
},
"reconstruct": {
"code": "greeting <- \"hello\"\nprint(greeting)",
"linesWithAutoSelected": 0,
"inlineWarnings": [],
".meta": {
"timing": 0
}
}
}
}
},
".meta": {
"timing": 193
}
}You can disable magic comments using the noMagicComments flag.
This query replaces the old request-slice message.
Implementation Details
Responsible for the execution of the Static Slice Query query is executeStaticSliceQuery in ./src/queries/catalog/static-slice-query/static-slice-query-executor.ts.
Currently maintained by Florian Sihler and Oliver Gerstl at Ulm University
Email | GitHub | Penguins | Portfolio
- 🧑💻 Developer Onboarding
- 💻 Setup
- 👓 Overview
- 🪟 Interfacing with flowR
- 🌋 Core
- 🧹 Testing & Linting (Benchmark Page)
⁉️ FAQ- ℹ️ Extra Information