Skip to content

Commit 31dd8c1

Browse files
owen-mcCopilot
andcommitted
Go: deprecate ParenExpr and remove all references
Since the extractor no longer produces ParenExpr nodes, deprecate the class so existing user code gets a warning rather than breaking, and remove all references from library code where it was used to look through parentheses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6345ef9 commit 31dd8c1

13 files changed

Lines changed: 21 additions & 108 deletions

File tree

go/docs/language/learn-ql/go/ast-class-reference.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,8 +450,6 @@ Miscellaneous
450450
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
451451
| ``...`` | `Ellipsis <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ellipsis.html>`__ | | |
452452
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
453-
| ``(``\ `Expr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html>`__\ ``)`` | `ParenExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$ParenExpr.html>`__ | | |
454-
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
455453
| `Ident <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ident.html>`__\ ``.``\ `Ident <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Ident.html>`__ | `SelectorExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$SelectorExpr.html>`__ | | |
456454
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
457455
| `Expr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html>`__\ ``[``\ `Expr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$Expr.html>`__\ ``]`` | `IndexExpr <https://help.semmle.com/qldoc/go/semmle/go/Expr.qll/type.Expr$IndexExpr.html>`__ | | |

go/ql/lib/change-notes/2026-08-13-cfg.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ category: breaking
2727
- `EvalCompoundAssignRhsInstruction` now also represents increment and
2828
decrement operations, and it and `EvalImplicitInitInstruction` directly
2929
represent their associated writes.
30+
* `ParenExpr` has been deprecated because parenthesized expressions are no
31+
longer extracted as separate AST nodes. The child expression now directly
32+
takes the place of the parenthesized expression.

go/ql/lib/semmle/go/Expr.qll

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,11 @@ class SliceLit extends ArrayOrSliceLit {
544544
}
545545

546546
/**
547-
* A parenthesized expression.
548-
*
549-
* Examples:
550-
*
551-
* ```go
552-
* (x + y)
553-
* ```
547+
* DEPRECATED: `ParenExpr` is no longer extracted. Parenthesized expressions are
548+
* transparent in the AST; the child expression takes the place of the parenthesized
549+
* expression directly.
554550
*/
555-
class ParenExpr extends @parenexpr, Expr {
551+
deprecated class ParenExpr extends @parenexpr, Expr {
556552
/** Gets the expression between parentheses. */
557553
Expr getExpr() { result = this.getChildExpr(0) }
558554

@@ -2149,8 +2145,6 @@ private predicate isTypeExprBottomUp(Expr e) {
21492145
or
21502146
e instanceof @indexexpr and isTypeExprBottomUp(e.getChildExpr(0))
21512147
or
2152-
isTypeExprBottomUp(e.(ParenExpr).getExpr())
2153-
or
21542148
isTypeExprBottomUp(e.(StarExpr).getBase())
21552149
or
21562150
isTypeExprBottomUp(e.(Ellipsis).getOperand())
@@ -2201,8 +2195,6 @@ private predicate isTypeExprTopDown(Expr e) {
22012195
or
22022196
e = any(SelectorExpr sel | isTypeExprTopDown(sel)).getBase()
22032197
or
2204-
e = any(ParenExpr pe | isTypeExprTopDown(pe)).getExpr()
2205-
or
22062198
e = any(StarExpr se | isTypeExprTopDown(se)).getBase()
22072199
or
22082200
e = any(Ellipsis ell | isTypeExprTopDown(ell)).getOperand()
@@ -2251,8 +2243,6 @@ class ReferenceExpr extends Expr {
22512243
not this = any(MethodSpec md).getNameExpr() and
22522244
not this = any(StructLit sl).getKey(_)
22532245
or
2254-
this.(ParenExpr).getExpr() instanceof ReferenceExpr
2255-
or
22562246
this.(StarExpr).getBase() instanceof ReferenceExpr
22572247
or
22582248
this instanceof DerefExpr
@@ -2302,7 +2292,6 @@ class ValueExpr extends Expr {
23022292
this instanceof BasicLit or
23032293
this instanceof FuncLit or
23042294
this instanceof CompositeLit or
2305-
this.(ParenExpr).getExpr() instanceof ValueExpr or
23062295
this instanceof SliceExpr or
23072296
this instanceof TypeAssertExpr or
23082297
this instanceof CallOrConversionExpr or

go/ql/lib/semmle/go/controlflow/ControlFlowGraph.qll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,6 @@ module ControlFlow {
282282
private predicate ensuresAux(Expr expr, boolean b) {
283283
expr = cond and b = outcome
284284
or
285-
expr = any(ParenExpr par | this.ensuresAux(par, b)).getExpr()
286-
or
287285
expr = any(NotExpr ne | this.ensuresAux(ne, b.booleanNot())).getOperand()
288286
or
289287
expr = any(LandExpr land | this.ensuresAux(land, true)).getAnOperand() and

go/ql/lib/semmle/go/controlflow/ControlFlowGraphImpl.qll

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -436,16 +436,6 @@ module CfgImpl {
436436
// pre-order means no in-order "invocation" node (and hence no inline
437437
// exceptional-exit edge) is created at the `defer` statement.
438438
e = any(Go::DeferStmt s).getCall()
439-
or
440-
// Parenthesized expressions are value-transparent (via `propagatesValue`)
441-
// and should not get an in-order evaluation node. Marking them as
442-
// pre-order prevents the shared library from auto-computing
443-
// `postOrInOrder` for them (which would create an unreachable In node).
444-
e instanceof Go::ParenExpr
445-
}
446-
447-
predicate propagatesValue(Ast::AstNode child, Ast::AstNode parent) {
448-
child = parent.(Go::ParenExpr).getExpr()
449439
}
450440

451441
predicate postOrInOrder(Ast::AstNode n) {

go/ql/lib/semmle/go/controlflow/IR.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,11 +1298,7 @@ module IR {
12981298
/**
12991299
* Gets the (final) instruction computing the value of `e`.
13001300
*/
1301-
Instruction evalExprInstruction(Expr e) {
1302-
result.(EvalInstruction).getExpr() = e
1303-
or
1304-
result = evalExprInstruction(e.(ParenExpr).getExpr())
1305-
}
1301+
Instruction evalExprInstruction(Expr e) { result.(EvalInstruction).getExpr() = e }
13061302

13071303
/**
13081304
* Gets the instruction corresponding to the initialization of `r`.

go/ql/lib/semmle/go/dataflow/Properties.qll

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ class Property extends TProperty {
3232
// then !test = !outcome ==> nd matches this
3333
this.checkOnExpr(test.(NotExpr).getOperand(), outcome.booleanNot(), nd)
3434
or
35-
// if test = outcome ==> nd matches this
36-
// then (test) = outcome ==> nd matches this
37-
this.checkOnExpr(test.(ParenExpr).getExpr(), outcome, nd)
38-
or
3935
// if test = true ==> nd matches this
4036
// then (test && e) = true ==> nd matches this
4137
outcome = true and

go/ql/src/experimental/IntegerOverflow/RangeAnalysis.qll

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ float getAnUpperBound(Expr expr) {
3131
if expr.isConst()
3232
then result = expr.getNumericValue()
3333
else (
34-
//if an expression with parenthesis, strip the parenthesis first
35-
exists(ParenExpr paren |
36-
paren = expr and
37-
result = getAnUpperBound(paren.stripParens())
38-
)
39-
or
4034
//if this expression is an identifier
4135
exists(SsaVariable v, Ident identifier |
4236
identifier = expr and
@@ -188,11 +182,6 @@ float getALowerBound(Expr expr) {
188182
result = expr.getIntValue() or
189183
result = expr.getExactValue().toFloat()
190184
else (
191-
exists(ParenExpr paren |
192-
paren = expr and
193-
result = getALowerBound(paren.stripParens())
194-
)
195-
or
196185
//if this expression is an identifer
197186
exists(SsaVariable v, Ident identifier |
198187
identifier = expr and
@@ -571,12 +560,6 @@ predicate ssaDependsOnExpr(SsaDefinition def, Expr expr) {
571560
if expr.isConst()
572561
then none()
573562
else (
574-
//if an expression with parenthesis, strip the parenthesis
575-
exists(ParenExpr paren |
576-
paren = expr and
577-
ssaDependsOnExpr(def, paren.stripParens())
578-
)
579-
or
580563
exists(Ident ident |
581564
ident = expr and
582565
getAUse(def) = ident
Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +0,0 @@
1-
consistencyOverview
2-
| missingInNodeForPostOrInOrder | 9 |
3-
missingInNodeForPostOrInOrder
4-
| WrongUsageOfUnsafe.go:19:21:19:27 | (...) |
5-
| WrongUsageOfUnsafe.go:36:21:36:27 | (...) |
6-
| WrongUsageOfUnsafe.go:57:21:57:27 | (...) |
7-
| WrongUsageOfUnsafe.go:79:21:79:30 | (...) |
8-
| WrongUsageOfUnsafe.go:113:21:113:30 | (...) |
9-
| WrongUsageOfUnsafe.go:131:21:131:30 | (...) |
10-
| WrongUsageOfUnsafe.go:151:21:151:30 | (...) |
11-
| WrongUsageOfUnsafe.go:169:25:169:34 | (...) |
12-
| WrongUsageOfUnsafe.go:191:21:191:30 | (...) |

0 commit comments

Comments
 (0)