Make a BinderAndDecls data type, at first just a wrapper around Binder.#1323
Open
Make a BinderAndDecls data type, at first just a wrapper around Binder.#1323
BinderAndDecls data type, at first just a wrapper around Binder.#1323Conversation
…nder`. Next we'll actually make decls part of it. But that will involve substantive changes. This first step just makes the type distinct from `Binder` so we can make all the administrative changes while still passing tests.
axch
reviewed
Jul 11, 2023
Comment on lines
+259
to
-275
| -- XXX: this is wrong. We need to add a mechanism for specifying commutativity | ||
| isAdditionMonoid :: BaseMonoid SimpIR n -> Maybe () | ||
| isAdditionMonoid monoid = do | ||
| BaseMonoid { baseEmpty = (Con (Lit l)) | ||
| , baseCombine = BinaryLamExpr (b1:>_) (b2:>_) body } <- Just monoid | ||
| , baseCombine = BinaryLamExpr _ _ _ } <- Just monoid | ||
| unless (_isZeroLit l) Nothing | ||
| PrimOp (BinOp op (Var b1') (Var b2')) <- exprBlock body | ||
| unless (op `elem` [P.IAdd, P.FAdd]) Nothing | ||
| case (binderName b1, atomVarName b1', binderName b2, atomVarName b2') of | ||
| -- Checking the raw names here because (i) I don't know how to convince the | ||
| -- name system to let me check the well-typed names (which is because b2 | ||
| -- might shadow b1), and (ii) there are so few patterns that I can just | ||
| -- enumerate them. | ||
| (UnsafeMakeName n1, UnsafeMakeName n1', UnsafeMakeName n2, UnsafeMakeName n2') -> do | ||
| when (n1 == n2) Nothing | ||
| unless ((n1 == n1' && n2 == n2') || (n1 == n2' && n2 == n1')) Nothing | ||
| Just () |
Collaborator
There was a problem hiding this comment.
That's true, but is there actually a reason to delete it? Without a check like this, the vectorizer will cheerfully reorder operations in arbitrary monoids, which may in principle emit incorrect code from a correct program.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Next we'll actually make decls part of it. But that will involve substantive changes. This first step just makes the type distinct from
Binderso we can make all the administrative changes while still passing tests.