@@ -1362,7 +1362,12 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex =
13621362 CursorTy -> do
13631363 rnd' <- cursorizeExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv rnd
13641364 after_indirection <- gensym " aft_indirection"
1365- LetE (d',[] , CursorTy , Ext $ WriteTaggedCursor aft_dloc rnd') <$>
1365+ casted_var <- gensym " cast"
1366+ let rnd_var = case rnd' of
1367+ VarE v -> v
1368+ _ -> error " Did not expected variable!"
1369+ LetE (casted_var, [] , CursorTy , Ext $ CastPtr rnd_var CursorTy ) <$>
1370+ LetE (d',[] , CursorTy , Ext $ WriteTaggedCursor aft_dloc (VarE casted_var)) <$>
13661371 LetE (after_indirection,[] , CursorTy , VarE d') <$> -- Ext $ AddCursor aft_dloc (L3.LitE 8)
13671372 go2 marker_added freeVarToVarEnv after_indirection from_rec_end aft_flocs rst
13681373
@@ -1587,13 +1592,34 @@ cursorizePackedExp freeVarToVarEnv lenv ddfs fundefs denv tenv senv ex =
15871592 Just var -> var
15881593 go freeVarToVarEnv tenv senv (DataConE from dcon [VarE locs_var])
15891594 else do
1590- start <- gensym " start"
1591- end <- gensym " end"
1592- return $ Di $
1593- (mkLets [(" _" ,[] ,ProdTy [] ,Ext (IndirectionBarrier tycon (((unwrapLocVar . toLocVar) from),((unwrapLocVar . toLocVar) from_reg),((unwrapLocVar . toLocVar) to),((unwrapLocVar . toLocVar) to_reg)))),
1594- (start, [] , CursorTy , VarE ((unwrapLocVar . toLocVar) from)),
1595- (end, [] , CursorTy , Ext $ AddCursor ((unwrapLocVar . toLocVar) from) (L3. LitE 9 ))]
1596- (MkProdE [VarE start, VarE end]))
1595+ case (toLocVar from) of
1596+ Single {} -> do
1597+ start <- gensym " start"
1598+ end <- gensym " end"
1599+ let from_var = case M. lookup (fromLocArgToFreeVarsTy from) freeVarToVarEnv of
1600+ Nothing -> error " Did not find variable for location!"
1601+ Just var -> var
1602+ let to_var = case M. lookup (fromLocArgToFreeVarsTy to) freeVarToVarEnv of
1603+ Nothing -> error " Did not find variable for location!"
1604+ Just var -> var
1605+ let reg_from_reg = fromLocVarToRegVar (toLocVar from_reg)
1606+ let reg_to_reg = fromLocVarToRegVar (toLocVar to_reg)
1607+ let from_reg_var = case M. lookup (fromRegVarToFreeVarsTy reg_from_reg) freeVarToVarEnv of
1608+ Nothing -> error " Did not find variable for location!"
1609+ Just var -> var
1610+ let to_reg_var = case M. lookup (fromRegVarToFreeVarsTy reg_to_reg) freeVarToVarEnv of
1611+ Nothing -> error " Did not find variable for location!"
1612+ Just var -> var
1613+ -- VS : [09/20/2025 -- For SoA case, indirection with gc need a bit more thinking]
1614+ -- One way could be to call indirection barrier seperately on every buffer/region
1615+ -- Then follow them seperately for every region in the case.
1616+ -- For now i'm erroring out but this needs more thought.
1617+ return $ Di $
1618+ (mkLets [(" _" ,[] ,ProdTy [] ,Ext (IndirectionBarrier tycon ((from_var),(from_reg_var),(to_var),(to_reg_var)))),
1619+ (start, [] , CursorTy , VarE (from_var)),
1620+ (end, [] , CursorTy , Ext $ AddCursor (from_var) (L3. LitE 9 ))]
1621+ (MkProdE [VarE start, VarE end]))
1622+ SoA _ flds -> error " Indirection when GC is enabled is not implemented for SoA! Please turn off the GC!"
15971623
15981624 AddFixed {} -> error " cursorizePackedExp: AddFixed not handled."
15991625
0 commit comments