New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support embedded pattern matching #460
Conversation
* Splits the modules D.A.A.Array.{Sugar,Representation} into several modules under the tree D.A.A.{Sugar,Representation}.* * Remove D.A.A.Trafo.Base, which was a lazy dumping ground for unrelated functionality * Move various definitions around into new modules, for example putting lift and rnf instances close to where those data structures are defined, rather than dumping them all into D.A.A.AST
# Conflicts: # src/Data/Array/Accelerate/AST.hs # src/Data/Array/Accelerate/Language.hs # src/Data/Array/Accelerate/Pretty/Graphviz.hs # src/Data/Array/Accelerate/Pretty/Print.hs # src/Data/Array/Accelerate/Smart.hs # src/Data/Array/Accelerate/Trafo/Fusion.hs # src/Data/Array/Accelerate/Trafo/LetSplit.hs # src/Data/Array/Accelerate/Trafo/Sharing.hs
* add tagsR field to Elt, to be used for pattern matching * Bool is no longer a primitive type
Don’t let cabal compile .c files, which perpetually leads to linking problems. Instead use TH to tell GHC about these files directly.
Technically this restriction is based on template-haskell, which is required to work around limitations of Cabal
also update TH generator to define patterns for simple product types in terms of Pattern
@@ -89,16 +83,14 @@ isRight x = tag x == 1 | |||
-- instead. | |||
-- | |||
fromLeft :: (Elt a, Elt b) => Exp (Either a b) -> Exp a | |||
fromLeft x = a | |||
where T3 _ a _ = asTuple x | |||
fromLeft (Exp e) = Exp $ SmartExp $ Prj PairIdxRight $ SmartExp $ Prj PairIdxLeft $ SmartExp $ Prj PairIdxRight e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought the goal of this PR was to allow users to define custom sum types. I hope they don't have to write this? Or is this line just avoiding generics, to be more efficient?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nah, this is just to define the unsafe fromLeft
and fromRight
functions. These existed from before this patch, I'm just updating them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess what I mean is, if defining 'your own' Either datatype (including all these 'isRight' and 'fromLeft' functions) is now possible on the user side, it would make sense to show off the `intended' way here instead of using Accelerate internals? Now that this vesion already works, that might be wasted effort, but I was surprised to see this after the paper promised a very neat interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, I understand what you mean now. I updated the functions in that module and added an example to the 'match' docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRight (Exp e) = Exp $ SmartExp $ (SmartExp $ Prj PairIdxLeft e)
Pair SmartExp Nil
I assume this is the same as something like:
isRight = match \case
Right_ _ -> True
Left_ _ -> False
This looks great! I was already planning on rewriting the sudoku solver, now that I know more about Accelerate (even changing a 'run' to 'runN' should already be an improvement I think, it now repeatedly compiles the same Acc program), and I might see what happens to the readability and performance if I use some nice ADTs instead of bitwise hacking.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. I'm just cheating because I know the tag bits for Right
and True
happen to be the same. I'll add a comment mentioning this.
At some point I went and added pattern synonyms to the sudokus code. Apparently I left it in a half-committed state, but I put it here: https://github.com/tmcdonell/Sudokus
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, that already looks much better! I'll put some more effort into that once I'm done :)
Looks good, I tested it on my delta stepping implementation and that worked fine (after changing the calls to
|
isZero :: Num a => Exp a -> Exp Bool
isZero 0 = True_
isZero _ = False_ will be desugared into: isZero x =
case x == fromInteger 0 of
True -> True_
False -> False_ We can't use the built in |
Thanks, that clears things up for me :). Ah, I thought that the type |
Description
This patch primarily adds support for sum data types in the Accelerate expression language.
The backends still need to be updated before this can be merged.
Motivation and context
Fixes: #87
Fixes: #100
Fixes: #249
Fixes: #263
How has this been tested?
Types of changes
Checklist: