Skip to content

Commit 8fc19b9

Browse files
authored
document compiler procs regarding & (#20257)
1 parent fdb781c commit 8fc19b9

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

compiler/ccgexprs.nim

+2-2
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ proc strLoc(p: BProc; d: TLoc): Rope =
11971197

11981198
proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
11991199
# <Nim code>
1200-
# s = 'Hello ' & name & ', how do you feel?' & 'z'
1200+
# s = "Hello " & name & ", how do you feel?" & 'z'
12011201
#
12021202
# <generated C code>
12031203
# {
@@ -1240,7 +1240,7 @@ proc genStrConcat(p: BProc, e: PNode, d: var TLoc) =
12401240

12411241
proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
12421242
# <Nim code>
1243-
# s &= 'Hello ' & name & ', how do you feel?' & 'z'
1243+
# s &= "Hello " & name & ", how do you feel?" & 'z'
12441244
# // BUG: what if s is on the left side too?
12451245
# <generated C code>
12461246
# {

compiler/hlo.nim

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#
99

1010
# This include implements the high level optimization pass.
11+
# included from sem.nim
1112

1213
when defined(nimPreviewSlimSystem):
1314
import std/assertions

compiler/transf.nim

+5
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,8 @@ proc getMergeOp(n: PNode): PSym =
806806
else: discard
807807

808808
proc flattenTreeAux(d, a: PNode, op: PSym) =
809+
## Optimizes away the `&` calls in the children nodes and
810+
## lifts the leaf nodes to the same level as `op2`.
809811
let op2 = getMergeOp(a)
810812
if op2 != nil and
811813
(op2.id == op.id or op.magic != mNone and op2.magic == op.magic):
@@ -898,6 +900,9 @@ proc transformExceptBranch(c: PTransf, n: PNode): PNode =
898900
result = transformSons(c, n)
899901

900902
proc commonOptimizations*(g: ModuleGraph; idgen: IdGenerator; c: PSym, n: PNode): PNode =
903+
## Merges adjacent constant expressions of the children of the `&` call into
904+
## a single constant expression. It also inlines constant expressions which are not
905+
## complex.
901906
result = n
902907
for i in 0..<n.safeLen:
903908
result[i] = commonOptimizations(g, idgen, c, n[i])

0 commit comments

Comments
 (0)