Skip to content

Commit d9b0542

Browse files
committed
ES: restructured as-pats in grin dir
1 parent 53d55d5 commit d9b0542

File tree

6 files changed

+48
-9
lines changed

6 files changed

+48
-9
lines changed

grin/src/Grin/ExtendedSyntax/Grin.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ instance FoldNames Val where
2525

2626
instance FoldNames BPat where
2727
foldNames f = \case
28-
VarPat v -> f v
29-
AsPat v val -> f v <> foldNames f val
28+
VarPat v -> f v
29+
AsPat t vs v -> f v <> foldNames (ConstTagNode t vs)
3030

3131

3232
instance FoldNames CPat where

grin/src/Grin/ExtendedSyntax/Lint.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ lint warningKinds mTypeEnv exp@(Program exts _) =
310310
when (isn't _OnlyVarPat bPat) $ do
311311
forM_ mTypeEnv $ \typeEnv -> do
312312
fromMaybe (pure ()) $ case bPat of
313-
AsPat v val -> do -- Maybe
314-
expectedPatType <- normalizeType <$> mTypeOfValTE typeEnv val
313+
AsPat tag fields v -> do -- Maybe
314+
expectedPatType <- normalizeType <$> mTypeOfValTE typeEnv (ConstTagNode tag fields)
315315
lhsType <- normalizeType <$> extract leftExp
316316
pure $ do -- Lint
317317
-- NOTE: This can still give false positive errors, because bottom-up typing can only approximate the result of HPT.

grin/src/Grin/ExtendedSyntax/Nametable.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ convert = second (view nametable) . flip runState emptyNS . cata build where
8686
ProgramF es defs -> Program <$> mapM external es <*> sequence defs
8787
DefF fn ps body -> Def <$> (nameToIdx fn) <*> (mapM nameToIdx ps) <*> body
8888
EBindF l (VarPat v) r -> EBind <$> l <*> (VarPat <$> nameToIdx v) <*> r
89-
EBindF l (AsPat var val) r -> EBind <$> l <*> (AsPat <$> nameToIdx var <*> value val) <*> r
89+
EBindF l (AsPat t vars v) r -> EBind <$> l <*> (AsPat <$> tag t <*> mapM nameToIdx vars <*> nameToIdx v) <*> r
9090
ECaseF v alts -> ECase <$> nameToIdx v <*> sequence alts
9191
SAppF v ps -> SApp <$> nameToIdx v <*> (mapM nameToIdx ps)
9292
SReturnF v -> SReturn <$> value v
@@ -107,7 +107,7 @@ restore (exp, nt) = cata build exp where
107107
ProgramF es defs -> Program (map rexternal es) defs
108108
DefF fn ps body -> Def (rname fn) (map rname ps) body
109109
EBindF l (VarPat v) r -> EBind l (VarPat $ rname v) r
110-
EBindF l (AsPat var val) r -> EBind l (AsPat (rname var) (rvalue val)) r
110+
EBindF l (AsPat t vs v) r -> EBind l (AsPat (rtag t) (map rname vs) (rname v)) r
111111
ECaseF v alts -> ECase (rname v) alts
112112
SAppF v ps -> SApp (rname v) (map rname ps)
113113
SReturnF v -> SReturn (rvalue v)

grin/src/Grin/ExtendedSyntax/Pretty.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,8 @@ instance Pretty Lit where
144144

145145
instance Pretty BPat where
146146
pretty = \case
147-
VarPat v -> pretty v
148-
AsPat v pat -> pretty pat <+> pretty '@' <+> pretty v
147+
VarPat v -> pretty v
148+
AsPat tag fields v -> pretty (ConstTagNode tag fields) <+> pretty '@' <+> pretty v
149149

150150
instance Pretty CPat where
151151
pretty = \case

grin/src/Grin/ExtendedSyntax/Statistics.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ statistics = cata $ \case
6767
e -> Data.Foldable.fold e
6868

6969
tagInBPat :: BPat -> Set.Set Tag
70-
tagInBPat (AsPat var (ConstTagNode t _)) = Set.singleton t
70+
tagInBPat (AsPat t _ _) = Set.singleton t
7171
tagInBPat _ = mempty
7272

7373

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
easy (without type env):
2+
- DONE: evaluated case elimination
3+
- DONE: trivial case elimination
4+
- DONE: update elimination
5+
- constant propagation
6+
7+
8+
easy (with type env):
9+
- non-shared elimination
10+
- DONE: CSE
11+
- SDFE, SDVE, SDPE
12+
- SCO
13+
- DFE, DPE
14+
15+
medium:
16+
- case copy propagation
17+
- copy propagation
18+
- DVE
19+
- dead data elimination
20+
21+
moderate:
22+
- case hoisting
23+
- inlining
24+
25+
hard:
26+
- arity raising
27+
- generalized unboxing
28+
29+
DONE: investigate update elimination vs CSE
30+
31+
Branches:
32+
33+
[x] 32-conversion-fix
34+
[ ] 32-alt-remove-unnamed
35+
[ ] 32-alt-analyses
36+
[ ] 32-trf-cse
37+
[ ] 32-trf-case-elims
38+
39+
[ ] 32-trf-copy-propagation

0 commit comments

Comments
 (0)