From 7a655ec458cc1dd7b760cdaadd65214981fb3b83 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 8 Oct 2026 12:15:31 +0100 Subject: [PATCH 1/2] Fix upgrade script --- .../upgrade.properties | 5 +- .../upgrade.ql | 74 +++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql diff --git a/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.properties b/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.properties index 768d62bb215d..1a8bbabd727f 100644 --- a/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.properties +++ b/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.properties @@ -1,2 +1,5 @@ description: Add @rangeelementexpr, grouping the loop variables of a range statement -compatibility: partial +compatibility: full + +exprs.rel: run upgrade.qlo new_exprs +has_location.rel: run upgrade.qlo new_has_location diff --git a/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql b/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql new file mode 100644 index 000000000000..b95a6e39a0dc --- /dev/null +++ b/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql @@ -0,0 +1,74 @@ +class Expr extends @expr { + string toString() { none() } +} + +class ExprParent extends @exprparent { + string toString() { none() } +} + +class RangeStmt extends @rangestmt { + string toString() { none() } +} + +class Location extends @location { + string toString() { none() } +} + +newtype TAddedExpr = TRangeElement(RangeStmt stmt) + +module Fresh = QlBuiltins::NewEntity; + +class TNewExpr = @expr or Fresh::EntityId; + +class NewExpr extends TNewExpr { + string toString() { none() } +} + +class TNewExprParent = @exprparent or Fresh::EntityId; + +class NewExprParent extends TNewExprParent { + string toString() { none() } +} + +class TNewLocatable = @locatable or Fresh::EntityId; + +class NewLocatable extends TNewLocatable { + string toString() { none() } +} + +predicate isRangeElementChild(ExprParent parent, int idx, RangeStmt range) { + parent = range and + idx in [0 .. 1] +} + +query predicate new_exprs(NewExpr id, int kind, NewExprParent parent, int idx) { + exists(RangeStmt range | + id = Fresh::map(TRangeElement(range)) and + kind = 55 and + parent = range and + idx = 0 + ) + or + exists(Expr oldId, int oldKind, ExprParent oldParent, int oldIdx | + exprs(oldId, oldKind, oldParent, oldIdx) and + id = oldId and + kind = oldKind and + idx = oldIdx + | + exists(RangeStmt range | isRangeElementChild(oldParent, oldIdx, range) | + parent = Fresh::map(TRangeElement(range)) + ) + or + not isRangeElementChild(oldParent, oldIdx, _) and + parent = oldParent + ) +} + +query predicate new_has_location(NewLocatable locatable, Location location) { + has_location(locatable, location) + or + exists(RangeStmt range | + locatable = Fresh::map(TRangeElement(range)) and + has_location(range, location) + ) +} From cf9d757776a44d393875af2709cc860bfe251064 Mon Sep 17 00:00:00 2001 From: Owen Mansel-Chan Date: Thu, 8 Oct 2026 13:56:53 +0100 Subject: [PATCH 2/2] Remove unnecessary variables --- .../upgrade.ql | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql b/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql index b95a6e39a0dc..cbf128324d8a 100644 --- a/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql +++ b/go/ql/lib/upgrades/5ff5325d274ae4f86defa195577bc7c1370b72fa/upgrade.ql @@ -49,17 +49,12 @@ query predicate new_exprs(NewExpr id, int kind, NewExprParent parent, int idx) { idx = 0 ) or - exists(Expr oldId, int oldKind, ExprParent oldParent, int oldIdx | - exprs(oldId, oldKind, oldParent, oldIdx) and - id = oldId and - kind = oldKind and - idx = oldIdx - | - exists(RangeStmt range | isRangeElementChild(oldParent, oldIdx, range) | + exists(ExprParent oldParent | exprs(id, kind, oldParent, idx) | + exists(RangeStmt range | isRangeElementChild(oldParent, idx, range) | parent = Fresh::map(TRangeElement(range)) ) or - not isRangeElementChild(oldParent, oldIdx, _) and + not isRangeElementChild(oldParent, idx, _) and parent = oldParent ) }