-
Notifications
You must be signed in to change notification settings - Fork 217
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
Inlinable and Logic Optimisations #614
Inlinable and Logic Optimisations #614
Conversation
…ll into fintan/new-map
Hey @Gabriel439 I can't seem to reproduce the error in ghci with the counterexample 🤔 Any chance you could give me a hand with it? Thanks! |
src/Dhall/Core.hs
Outdated
deriving (Functor, Foldable, Generic, Traversable, Show, Eq, Data) | ||
deriving (Foldable, Generic, Traversable, Show, Data) | ||
|
||
instance (Eq s, Eq a) => Eq (Expr s a) where |
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.
How critical is the INLINABLE
Eq
instance for performance? The reason I ask is that it's going to be the most error-prone instance to maintain due to the wildcard match at the end, so if we forget to add Eq
support for a newly-introduced constructor the compiler won't warn us.
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.
Good point! I don't think it adds much. I can remove it :)
src/Dhall/Map.hs
Outdated
> | ||
> head k (singleton k v) = Just (k, v) | ||
-} | ||
head :: Ord k => Map k v -> Maybe (k, v) |
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.
Instead of head
/tail
we could do:
uncons :: Ord k => Map k v -> Maybe (k, v, Map k v)
... that way we don't need to pattern match on a Maybe
twice since we know that if the head
succeeds then the tail
will always succeed, too
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.
💯
|
||
-- | Traverse all of the key-value pairs in a `Map`, in their original order | ||
traverseWithKey | ||
:: Ord k => Applicative f => (k -> a -> f b) -> Map k a -> f (Map k b) | ||
traverseWithKey f m = fmap fromList (traverse f' (toList m)) | ||
where | ||
f' (k, a) = fmap ((,) k) (f k a) | ||
{-# INLINABLE traverseWithKey #-} | ||
|
||
traverseWithKey_ |
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.
Now that we have this, we no longer need the intermediate Process
newtype
defined in the Dhall.TypeCheck
module. I only added that type just for the Monoid
instance, but if we replace foldMapWithKey
with traverseWithKey_
then we don't need to wrap the process
action in the Process
newtype
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.
Also, don't forget to add documentation for the traverseWithKey_
function
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 interesting! I'll check that out
@FintanH: I can reproduce the error:
It's because of the change you made to the |
I also added the |
Thank you! 🙂 |
* Cleanup * Centralize all `Map`-related operations * Use custom `Map` implementation * Inline and specialise functions * Custom Eq. Use inlinable * Mark inlinable * Remove SCC annotations * mappend from Semigroup * mappend from Semigroup * Clean up of Map, Expr Eq, and TypeCheck
INLINABLE
pragmas to newDhall.Map
functions, as well asEq
andFunctor
instances forExpr
Core
normalization logic to just look at thehead
instead of transforming the wholeMap
into a list