summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorClyybber <darkmine956@gmail.com>2021-09-24 14:59:48 +0200
committerGitHub <noreply@github.com>2021-09-24 14:59:48 +0200
commitf7d642f2f3925feb5addc315eb59caf326cad470 (patch)
tree0b065d77ee9f0cff2aad32193462573dd903246c
parent5d315ebcc2d4f46b4a74c6ab10146466c894b9de (diff)
downloadNim-f7d642f2f3925feb5addc315eb59caf326cad470.tar.gz
[backport] arc: improve compile time of (nested) loops (#18890)
-rw-r--r--compiler/dfa.nim11
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/dfa.nim b/compiler/dfa.nim
index 65c483e9c..0539f6699 100644
--- a/compiler/dfa.nim
+++ b/compiler/dfa.nim
@@ -308,6 +308,11 @@ when true:
     # We unroll every loop 3 times. We emulate 0, 1, 2 iterations
     # through the loop. We need to prove this is correct for our
     # purposes. But Herb Sutter claims it is. (Proof by authority.)
+    #
+    # EDIT: Actually, we only need to unroll 2 times
+    # because Nim doesn't have a way of breaking/goto-ing into
+    # a loop iteration. Unrolling 2 times is much better for compile
+    # times of nested loops than 3 times, so we do that here.
     #[
     while cond:
       body
@@ -347,12 +352,12 @@ when true:
       # 'while true' is an idiom in Nim and so we produce
       # better code for it:
       withBlock(nil):
-        for i in 0..2:
+        for i in 0..1:
           c.gen(n[1])
     else:
       withBlock(nil):
-        var endings: array[3, TPosition]
-        for i in 0..2:
+        var endings: array[2, TPosition]
+        for i in 0..1:
           c.gen(n[0])
           endings[i] = c.forkI(n)
           c.gen(n[1])