Skip to content

Commit 800c17e

Browse files
committed
ES: analyses as-pats
1 parent f2dc0a0 commit 800c17e

File tree

4 files changed

+7
-42
lines changed

4 files changed

+7
-42
lines changed

grin/src/AbstractInterpretation/ExtendedSyntax/CreatedBy/CodeGen.hs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ producesNode (Undefined T_NodeSet{}) = True
168168
producesNode _ = False
169169

170170
asPatternDataflow :: IR.Reg -> BPat -> CG ()
171-
asPatternDataflow r asPat@(AsPat _ asVal) = case asVal of
172-
Unit -> pure ()
173-
Lit{} -> pure ()
174-
Var v -> addReg v r
175-
ConstTagNode tag args -> do
171+
asPatternDataflow r asPat@(AsPat tag args _) = do
176172
irTag <- getTag tag
177173
bindInstructions <- forM (zip [1..] args) $ \(idx, arg) -> do
178174
argReg <- newReg
@@ -187,7 +183,6 @@ asPatternDataflow r asPat@(AsPat _ asVal) = case asVal of
187183
, srcReg = r
188184
, instructions = concat bindInstructions
189185
}
190-
valPat -> error $ "unsupported @pattern: " ++ show (PP asPat)
191186
asPatternDataflow _ pat = error $ "not @pattern: " ++ show (PP pat)
192187

193188
{- NOTE: para is needed to specify the order of evalution of the lhs and rhs on binds.
@@ -227,17 +222,10 @@ codeGen e = flip evalState emptyCGState $ para folder e >> mkCByProgramM where
227222
cgRhs
228223

229224
-- NOTE: @patterns
230-
EBindF (lhs, cgLhs) asPat@(AsPat var valPat) (_, cgRhs) -> do
225+
EBindF (lhs, cgLhs) asPat@(AsPat tag args var) (_, cgRhs) -> do
231226
lhsRes <- cgLhs
232227
case lhsRes of
233-
Z -> do
234-
r <- newReg
235-
emit IR.Set {dstReg = r, constant = IR.CSimpleType unitType}
236-
addReg var r
237-
case valPat of
238-
Unit -> pure ()
239-
Var inner -> addReg inner r
240-
_ -> error $ "pattern mismatch at CreatedBy bind codegen, expected Unit got " ++ show (PP valPat)
228+
Z -> error $ "pattern mismatch at CreatedBy bind codegen, expected Unit got " ++ show (PP $ ConstTagNode tag args)
241229
R r -> do
242230
case lhs of
243231
SReturn val | producesNode val -> do

grin/src/AbstractInterpretation/ExtendedSyntax/EffectTracking/CodeGen.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ codeGenM = cata folder where
6666
let R rhsReg = rhs
6767

6868
case bPat of
69-
VarPat var -> addReg var lhsReg
70-
AsPat var _ -> addReg var lhsReg
69+
VarPat var -> addReg var lhsReg
70+
AsPat _ _ var -> addReg var lhsReg
7171

7272
emit IR.Move { srcReg = lhsReg, dstReg = rhsReg }
7373
pure $ R rhsReg

grin/src/AbstractInterpretation/ExtendedSyntax/HeapPointsTo/CodeGen.hs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,28 +176,14 @@ codeGenM = cata folder where
176176
EBindF leftExp bpat rightExp -> do
177177
leftExp >>= \case
178178
Z -> case bpat of
179-
AsPat varName Unit -> do
180-
r <- newReg
181-
emit IR.Set {dstReg = r, constant = IR.CSimpleType unitType}
182-
addReg varName r
183179
VarPat varName -> do
184180
r <- newReg
185181
emit IR.Set {dstReg = r, constant = IR.CSimpleType unitType}
186182
addReg varName r
187183
_ -> error $ "pattern mismatch at HPT bind codegen, Unit cannot be matched against " ++ show bpat
188184
R r -> case bpat of -- QUESTION: should the evaluation continue if the pattern does not match yet?
189185
VarPat varName -> addReg varName r
190-
AsPat varName Unit -> do
191-
addReg varName r
192-
pure () -- TODO: is this ok? or error?
193-
-- NOTE: I think this is okay. Could be optimised though (since we already know the result)?
194-
AsPat varName Lit{} -> do
195-
addReg varName r
196-
pure () -- TODO: is this ok? or error?
197-
AsPat v1 (Var v2) -> do
198-
addReg v1 r
199-
addReg v2 r
200-
AsPat varName (ConstTagNode tag args) -> do
186+
AsPat tag args varName -> do
201187
addReg varName r
202188
irTag <- getTag tag
203189
bindInstructions <- forM (zip [0..] args) $ \(idx, name) -> do

grin/src/AbstractInterpretation/ExtendedSyntax/LiveVariable/CodeGen.hs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,7 @@ codeGenM e = (cata folder >=> const setMainLive) e
237237

238238
case bPat of
239239
VarPat v -> mkRegsThenVarPatternDataFlow v
240-
AsPat v Unit -> do
241-
setBasicValLive lhsReg
242-
mkRegsThenVarPatternDataFlow v
243-
AsPat v Lit{} -> do
244-
setBasicValLive lhsReg
245-
mkRegsThenVarPatternDataFlow v
246-
AsPat v1 (Var v2) -> do
247-
mkRegsThenVarPatternDataFlow v1
248-
mkRegsThenVarPatternDataFlow v2
249-
AsPat v (ConstTagNode tag args) -> do
240+
AsPat tag args v -> do
250241
irTag <- getTag tag
251242
setTagLive irTag lhsReg
252243
bindInstructions <- codeGenBlock_ $ forM (zip [1..] args) $ \(idx, arg) -> do

0 commit comments

Comments
 (0)