Skip to content

Commit c10f84b

Browse files
authored
fixes #24053; fixes #18288; relax reorder with push/pop pragmas restrictions; no crossing push/pop barriers (#24061)
fixes #24053; fixes #18288 makes push pragmas depend on each node before it and nodes after it depend on it
1 parent 4a548de commit c10f84b

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

compiler/reorder.nim

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,14 @@ proc intersects(s1, s2: IntSet): bool =
322322
if s2.contains(a):
323323
return true
324324

325+
proc hasPushOrPopPragma(n: DepN): bool =
326+
# Checks if the tree node has some pragmas that do not
327+
# play well with reordering, like the push/pop pragma
328+
# no crossing for push/pop barrier
329+
let a = n.pnode
330+
result = a.kind == nkPragma and a[0].kind == nkIdent and
331+
(a[0].ident.s == "push" or a[0].ident.s == "pop")
332+
325333
proc buildGraph(n: PNode, deps: seq[(IntSet, IntSet)]): DepG =
326334
# Build a dependency graph
327335
result = newSeqOfCap[DepN](deps.len)
@@ -363,6 +371,13 @@ proc buildGraph(n: PNode, deps: seq[(IntSet, IntSet)]): DepG =
363371
for dep in deps[i][0]:
364372
if dep in declares:
365373
ni.expls.add "one declares \"" & idNames[dep] & "\" and the other defines it"
374+
elif hasPushOrPopPragma(nj):
375+
# Every node that comes after a push/pop pragma must
376+
# depend on it; vice versa
377+
if j < i:
378+
ni.kids.add nj
379+
else:
380+
nj.kids.add ni
366381
else:
367382
for d in declares:
368383
if uses.contains(d):
@@ -403,18 +418,7 @@ proc getStrongComponents(g: var DepG): seq[seq[DepN]] =
403418
if v.idx < 0:
404419
strongConnect(v, idx, s, result)
405420
406-
proc hasForbiddenPragma(n: PNode): bool =
407-
# Checks if the tree node has some pragmas that do not
408-
# play well with reordering, like the push/pop pragma
409-
result = false
410-
for a in n:
411-
if a.kind == nkPragma and a[0].kind == nkIdent and
412-
a[0].ident.s == "push":
413-
return true
414-
415421
proc reorder*(graph: ModuleGraph, n: PNode, module: PSym): PNode =
416-
if n.hasForbiddenPragma:
417-
return n
418422
var includedFiles = initIntSet()
419423
let mpath = toFullPath(graph.config, module.fileIdx)
420424
let n = expandIncludes(graph, module, n, mpath,

tests/modules/treorder.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ defined
88

99
{.experimental: "codeReordering".}
1010

11+
{.push callconv: stdcall.}
12+
1113
proc bar(x: T)
1214

1315
proc foo() =
@@ -41,3 +43,5 @@ using
4143
my, omy: int
4244

4345
goo(3, 4)
46+
47+
{.pop.}

0 commit comments

Comments
 (0)