@@ -322,6 +322,14 @@ proc intersects(s1, s2: IntSet): bool =
322
322
if s2.contains(a):
323
323
return true
324
324
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
+
325
333
proc buildGraph(n: PNode, deps: seq [(IntSet, IntSet)]): DepG =
326
334
# Build a dependency graph
327
335
result = newSeqOfCap[DepN](deps.len)
@@ -363,6 +371,13 @@ proc buildGraph(n: PNode, deps: seq[(IntSet, IntSet)]): DepG =
363
371
for dep in deps[i][0 ]:
364
372
if dep in declares:
365
373
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
366
381
else :
367
382
for d in declares:
368
383
if uses.contains(d):
@@ -403,18 +418,7 @@ proc getStrongComponents(g: var DepG): seq[seq[DepN]] =
403
418
if v.idx < 0:
404
419
strongConnect(v, idx, s, result )
405
420
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
-
415
421
proc reorder*(graph: ModuleGraph, n: PNode, module: PSym): PNode =
416
- if n.hasForbiddenPragma:
417
- return n
418
422
var includedFiles = initIntSet()
419
423
let mpath = toFullPath(graph.config, module.fileIdx)
420
424
let n = expandIncludes(graph, module, n, mpath,
0 commit comments