Skip to content

Commit ee020e5

Browse files
redsun82Copilot
andcommitted
Rust: scrub deleted-node references in downgrade script
A full new->old->new dataset upgrade/downgrade round-trip surfaced dangling references: deleting the new node kinds left `macro_call_macro_call_expansions` rows (and potentially `comments` rows) pointing at now-undefined `@ast_node`s. These are the only two relations with a generic `@ast_node`-typed value column, so the downgrade now drops rows in both that reference a deleted node, alongside the existing `locatable_locations` scrub. `codeql dataset check` is now clean at every stage of the round-trip. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 890cb55d-0437-4bd7-9268-87b8897ada01
1 parent fb47497 commit ee020e5

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

rust/downgrades/852696f20117c338fbb4e6a4f5ed69df79682c37/downgrade.ql

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class Location extends @location_default {
77
}
88

99
// Genuinely-new node kinds with no representation in the old schema. Their own child relations are
10-
// dropped via `delete` in upgrade.properties; here we additionally drop their locations so no
11-
// dangling `locatable_locations` rows remain.
12-
private predicate deletedElement(Element id) {
10+
// dropped via `delete` in upgrade.properties; the references to them from `@ast_node`-typed columns
11+
// (`macro_call_macro_call_expansions`, `comments`) and their `locatable_locations` are scrubbed
12+
// below.
13+
private predicate deletedNode(Element id) {
1314
deref_pats(id) or
1415
not_nulls(id) or
1516
include_bytes_exprs(id) or
@@ -19,6 +20,14 @@ private predicate deletedElement(Element id) {
1920
visibility_inners(id)
2021
}
2122

23+
// A deleted node, plus any comment attached to one: dropping the comment's `comments` row would
24+
// otherwise leave its `locatable_locations` row dangling.
25+
private predicate deletedElement(Element id) {
26+
deletedNode(id)
27+
or
28+
exists(Element parent | comments(id, parent, _) and deletedNode(parent))
29+
}
30+
2231
// A `@name` used as a format argument's name. The old schema represents these as dedicated text-less
2332
// `@format_args_arg_name` placeholders, so we repurpose these ids into that entity table and drop
2433
// them (and their text) from `names`/`name_texts`.
@@ -48,3 +57,14 @@ query predicate new_name_texts(Element id, string text) {
4857
query predicate new_locatable_locations(Element id, Location location) {
4958
locatable_locations(id, location) and not deletedElement(id)
5059
}
60+
61+
// `macro_call_macro_call_expansions` and `comments` are the only two relations with a generic
62+
// `@ast_node`-typed value column, so a deleted node reachable through a macro expansion or as a
63+
// comment's parent would otherwise dangle here.
64+
query predicate new_macro_call_macro_call_expansions(Element macroCall, Element expansion) {
65+
macro_call_macro_call_expansions(macroCall, expansion) and not deletedNode(expansion)
66+
}
67+
68+
query predicate new_comments(Element id, Element parent, string text) {
69+
comments(id, parent, text) and not deletedNode(parent)
70+
}

rust/downgrades/852696f20117c338fbb4e6a4f5ed69df79682c37/upgrade.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ names.rel: run downgrade.ql new_names
1212
name_texts.rel: run downgrade.ql new_name_texts
1313

1414
locatable_locations.rel: run downgrade.ql new_locatable_locations
15+
macro_call_macro_call_expansions.rel: run downgrade.ql new_macro_call_macro_call_expansions
16+
comments.rel: run downgrade.ql new_comments
1517

1618
deref_pats.rel: delete
1719
deref_pat_pats.rel: delete

0 commit comments

Comments
 (0)