From 94f6ac98de3abb1146b971fd0a6749d191ed20db Mon Sep 17 00:00:00 2001
From: Slava Pestov <slava@factorcode.org>
Date: Thu, 29 Jul 2010 21:06:48 -0400
Subject: [PATCH] compiler.cfg.linear-scan: fix bad interaction between
 inactive intervals and sync points

---
 .../compiler/cfg/linear-scan/allocation/allocation.factor  | 2 +-
 .../compiler/cfg/linear-scan/assignment/assignment.factor  | 7 ++++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/basis/compiler/cfg/linear-scan/allocation/allocation.factor b/basis/compiler/cfg/linear-scan/allocation/allocation.factor
index f102a6ae9c..89c03b34f3 100644
--- a/basis/compiler/cfg/linear-scan/allocation/allocation.factor
+++ b/basis/compiler/cfg/linear-scan/allocation/allocation.factor
@@ -62,8 +62,8 @@ M: live-interval handle
 
 M: sync-point handle ( sync-point -- )
     [ n>> deactivate-intervals ]
-    [ handle-sync-point ]
     [ n>> activate-intervals ]
+    [ handle-sync-point ]
     tri ;
 
 : smallest-heap ( heap1 heap2 -- heap )
diff --git a/basis/compiler/cfg/linear-scan/assignment/assignment.factor b/basis/compiler/cfg/linear-scan/assignment/assignment.factor
index ef02b890f7..365d4e2f21 100644
--- a/basis/compiler/cfg/linear-scan/assignment/assignment.factor
+++ b/basis/compiler/cfg/linear-scan/assignment/assignment.factor
@@ -39,6 +39,11 @@ SYMBOL: pending-interval-assoc
         drop leader vreg rep-of lookup-spill-slot
     ] unless ;
 
+ERROR: not-spilled-error vreg ;
+
+: vreg>spill-slot ( vreg -- spill-slot )
+    dup vreg>reg dup spill-slot? [ nip ] [ drop leader not-spilled-error ] if ;
+
 : vregs>regs ( vregs -- assoc )
     [ f ] [ [ dup vreg>reg ] H{ } map>assoc ] if-empty ;
 
@@ -144,7 +149,7 @@ M: vreg-insn assign-registers-in-insn
 
 M: gc-map-insn assign-registers-in-insn
     [ [ assign-insn-defs ] [ assign-insn-uses ] [ assign-insn-temps ] tri ]
-    [ gc-map>> [ [ vreg>reg ] map ] change-gc-roots drop ]
+    [ gc-map>> [ [ vreg>spill-slot ] map ] change-gc-roots drop ]
     bi ;
 
 M: insn assign-registers-in-insn drop ;