 ! Map vregs -> alias classes
 SYMBOL: vregs>acs
 
-ERROR: vreg-ac-not-set vreg ;
+! Map alias classes -> sequence of vregs
+SYMBOL: acs>vregs
+
+! Alias class for objects which are loaded from the data stack
+! or other object slots. We pessimistically assume that they
+! can all alias each other.
+SYMBOL: heap-ac
+
+: ac>vregs ( ac -- vregs )
+    acs>vregs get [ drop V{ } clone ] cache ;
 
 : vreg>ac ( vreg -- ac )
     #! Only vregs produced by ##allot, ##peek and ##slot can
     #! ever be used as valid inputs to ##slot and ##set-slot,
     #! so we assert this fact by not giving alias classes to
     #! other vregs.
-    vregs>acs get ?at [ vreg-ac-not-set ] unless ;
-
-! Map alias classes -> sequence of vregs
-SYMBOL: acs>vregs
-
-: ac>vregs ( ac -- vregs ) acs>vregs get at ;
+    vregs>acs get [ heap-ac get [ ac>vregs push ] keep ] cache ;
 
 : aliases ( vreg -- vregs )
     #! All vregs which may contain the same value as vreg.

: next-ac ( -- n )
    ac-counter [ dup 1 + ] change ;

! Alias class for objects which are loaded from the data stack
! or other object slots. We pessimistically assume that they
! can all alias each other.
SYMBOL: heap-ac

: set-heap-ac ( vreg -- ) heap-ac get set-ac ;

: set-new-ac ( vreg -- ) next-ac set-ac ;

: kill-constant-set-slot ( slot# vreg -- )
    [ live-slots get at delete-at ] with each-alias ;

:: record-constant-set-slot ( insn# slot# vreg -- )
    vreg recent-stores get at :> recent-stores
    slot# recent-stores at [ dead-store ] when*
    insn# slot# recent-stores set-at ;


    ! inserted yet.
    dup [
        { int-rep tagged-rep } member?
        [ drop ] [ set-new-ac ] if
    ] each-def-rep ;

M: vreg-insn analyze-aliases
    def-acs ;

M: ##allocation analyze-aliases
    #! A freshly allocated object is distinct from any other
