Skip to content

[Query] Dice

github-actions[bot] edited this page Nov 8, 2026 · 1 revision

Generated from 'wiki-query.ts' on 2026-11-08, 08:41:45 UTC (v2.17.4), do not edit directly.

Dice Query [overview]

Reduces the code to the parts that carry information from a given start point to a given end point.
This query is requested with the type dice.
Run in the REPL: :query @dice (<crit>;...->crit;...)[icIB] <code | file://path>

While the Static Slice Query answers "what affects this point?" (or "what does this point affect?"), a dice answers the two-sided question: which parts of the program carry information from A to B? It is the intersection of a forward slice seeded at from and a backward slice seeded at to, so only the code that lies on some dependency path between the two criteria survives.

Both from and to are arrays of slicing criteria, just like for the Static Slice Query. Unlike that query, there is no direction property: the direction is already fixed by the from→to pairing.

Consider the following code:

x <- 1
y <- 2
z <- x + y
w <- z * 2
print(z)

Asking what connects the definition of x to the definition of z drops y <- 2 (it never depends on x) as well as w <- z * 2 and print(z) (they are not on a path into the to criterion):

[ { "type": "dice",   "from": [ "1@x" ],   "to": [ "3@z" ] } ]

(This can be shortened to @dice (1@x->3@z) "x <- 1\ny <- 2\nz <- x + y\nw <- z * 2\nprint(z)" when used with the REPL command :query).

Results (prettified and summarized):

x <- 1
z <- x + y

Show Detailed Results as Json

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

The JSON contains the ids of the nodes in question (see the Interface wiki page).

{"dice":{".meta":{},"results":{"1@x->3@z":{"slice":{"timesHitThreshold":0,"result":[0,2,7,9,10,6],"slicedFor":[0,6],".meta":{}},"reconstruct":{"code":"x <- 1\nz <- x + y","files":[{"code":"x <- 1\nz <- x + y"}],"linesWithAutoSelected":0,".meta":{}}}}},".meta":{}}

Beyond from and to, the dice query understands the same options as the Static Slice Query (noReconstruction, noMagicComments, inlineSources, inlineFull, and includeCallees), as both share the SliceQueryOptions of ./src/queries/catalog/slice-query-options.ts.

Multiple Criteria per Side

Each side accepts several criteria, which are seeded together:

[ { "type": "dice",   "from": [ "1@x",    "2@y" ],   "to": [ "5@print" ] } ]

Results (prettified and summarized):

x <- 1
y <- 2
z <- x + y
print(z)

Show Detailed Results as Json

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

The JSON contains the ids of the nodes in question (see the Interface wiki page).

{"dice":{".meta":{},"results":{"1@x,2@y->5@print":{"slice":{"timesHitThreshold":0,"result":[0,3,5,8,9,10,6,17,19,2,7],"slicedFor":[0,3,19],".meta":{}},"reconstruct":{"code":"x <- 1\ny <- 2\nz <- x + y\nprint(z)","files":[{"code":"x <- 1\ny <- 2\nz <- x + y\nprint(z)"}],"linesWithAutoSelected":0,".meta":{}}}}},".meta":{}}
Implementation Details

The Dice Query is executed by executeDiceQuery.

Clone this wiki locally

⌂ 换网址