document compiler procs regarding & (#20257)

This commit is contained in:
ringabout 2022-08-22 16:11:43 +08:00 • committed by GitHub
commit 8fc19b9e12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 2 deletions

View file

@ -806,6 +806,8 @@ proc getMergeOp(n: PNode): PSym =
else: discard
proc flattenTreeAux(d, a: PNode, op: PSym) =
## Optimizes away the `&` calls in the children nodes and
## lifts the leaf nodes to the same level as `op2`.
let op2 = getMergeOp(a)
if op2 != nil and
(op2.id == op.id or op.magic != mNone and op2.magic == op.magic):
@ -898,6 +900,9 @@ proc transformExceptBranch(c: PTransf, n: PNode): PNode =
result = transformSons(c, n)
proc commonOptimizations*(g: ModuleGraph; idgen: IdGenerator; c: PSym, n: PNode): PNode =
## Merges adjacent constant expressions of the children of the `&` call into
## a single constant expression. It also inlines constant expressions which are not
## complex.
result = n
for i in 0..<n.safeLen:
result[i] = commonOptimizations(g, idgen, c, n[i])