From 8d254a5945c5cb7612dff2a53be8f8d12b846d60 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Fri, 6 Sep 2024 17:26:24 +0800 Subject: [PATCH] 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 (cherry picked from commit c10f84b9d75b6a6f2a187132e9c27c7693648bad) --- compiler/reorder.nim | 25 +++++++++++++++---------- tests/modules/treorder.nim | 4 ++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/compiler/reorder.nim b/compiler/reorder.nim index 4ad3f12194..d52d64d030 100644 --- a/compiler/reorder.nim +++ b/compiler/reorder.nim @@ -319,6 +319,14 @@ proc intersects(s1, s2: IntSet): bool = if s2.contains(a): return true +proc hasPushOrPopPragma(n: DepN): bool = + # Checks if the tree node has some pragmas that do not + # play well with reordering, like the push/pop pragma + # no crossing for push/pop barrier + let a = n.pnode + result = a.kind == nkPragma and a[0].kind == nkIdent and + (a[0].ident.s == "push" or a[0].ident.s == "pop") + proc buildGraph(n: PNode, deps: seq[(IntSet, IntSet)]): DepG = # Build a dependency graph result = newSeqOfCap[DepN](deps.len) @@ -360,6 +368,13 @@ proc buildGraph(n: PNode, deps: seq[(IntSet, IntSet)]): DepG = for dep in deps[i][0]: if dep in declares: ni.expls.add "one declares \"" & idNames[dep] & "\" and the other defines it" + elif hasPushOrPopPragma(nj): + # Every node that comes after a push/pop pragma must + # depend on it; vice versa + if j < i: + ni.kids.add nj + else: + nj.kids.add ni else: for d in declares: if uses.contains(d): @@ -399,17 +414,7 @@ proc getStrongComponents(g: var DepG): seq[seq[DepN]] = if v.idx < 0: strongConnect(v, idx, s, result) -proc hasForbiddenPragma(n: PNode): bool = - # Checks if the tree node has some pragmas that do not - # play well with reordering, like the push/pop pragma - for a in n: - if a.kind == nkPragma and a[0].kind == nkIdent and - a[0].ident.s == "push": - return true - proc reorder*(graph: ModuleGraph, n: PNode, module: PSym): PNode = - if n.hasForbiddenPragma: - return n var includedFiles = initIntSet() let mpath = toFullPath(graph.config, module.fileIdx) let n = expandIncludes(graph, module, n, mpath, diff --git a/tests/modules/treorder.nim b/tests/modules/treorder.nim index 286b50e227..ff0b2e0710 100644 --- a/tests/modules/treorder.nim +++ b/tests/modules/treorder.nim @@ -8,6 +8,8 @@ defined {.experimental: "codeReordering".} +{.push callconv: stdcall.} + proc bar(x: T) proc foo() = @@ -41,3 +43,5 @@ using my, omy: int goo(3, 4) + +{.pop.}