Intern Qualified, use HashMaps for type checking environment#9
Intern Qualified, use HashMaps for type checking environment#9kozak wants to merge 22 commits intorestaumaticfrom
Conversation
| {-# LANGUAGE ViewPatterns #-} | ||
| {-# LANGUAGE ScopedTypeVariables #-} | ||
|
|
||
| module Language.PureScript.Interner where |
There was a problem hiding this comment.
It's taken from https://github.com/reflex-frp/hash-cons/blob/main/src/Data/HashCons/Internal.hs , right?
Are there modifications? Maybe add a comment indicating the source?
Also, the license probably should be copied here or something
| | UnusedIdent | ||
| -- | | ||
| -- A generated name used only for internal transformations | ||
| -- A generated name used only for hashConsal transformations |
There was a problem hiding this comment.
A clbuttic mistake
| -- A generated name used only for hashConsal transformations | |
| -- A generated name used only for internal transformations |
| instance Show ModuleName where | ||
| show (ModuleName i) = T.unpack $ unHashCons i | ||
|
|
||
| instance Ord ModuleName where | ||
| compare (ModuleName a) (ModuleName b) = compare (unHashCons a) (unHashCons b) | ||
|
|
||
| instance Serialise ModuleName where | ||
| encode (ModuleName i) = encode (unHashCons i) | ||
| decode = ModuleName . hashCons <$> decode | ||
|
|
||
| instance Hashable ModuleName where | ||
| hash (ModuleName i) = hash i | ||
| hashWithSalt s (ModuleName i) = hashWithSalt s i |
There was a problem hiding this comment.
These instances can probably be handled via newtype deriving.
| show (ModuleName i) = T.unpack $ unHashCons i | ||
|
|
||
| instance Ord ModuleName where | ||
| compare (ModuleName a) (ModuleName b) = compare (unHashCons a) (unHashCons b) |
There was a problem hiding this comment.
Is there a reason we don't use the "optimized" hash-based Ord? Do we rely on deterministic ordering somewhere?
| -- | ||
| data Qualified a = Qualified QualifiedBy a | ||
| deriving (Show, Eq, Ord, Functor, Foldable, Traversable, Generic) | ||
| data Qualified' a = Qualified' QualifiedBy a |
There was a problem hiding this comment.
I don't know what the convention is in Haskell, but in Rust-land such types ("guts" of a type where the public version is wrapped in something) are named by adding an Inner suffix, i.e. QualifiedInner
|
|
||
| instance NFData a => NFData (Qualified a) | ||
| instance Serialise a => Serialise (Qualified a) | ||
| mapQualified :: Hashable b => (a -> b) -> Qualified a -> Qualified b |
There was a problem hiding this comment.
It is a little annoying (lots of changes caused by losing the Functor instance).
If only the Haskell ecosystem used constrained functors by default...
| byModule = do | ||
| (mn, a) <- parseJSON2 v | ||
| pure $ Qualified (ByModuleName mn) a | ||
| pure $ mkQualified_ (ByModuleName mn) a |
There was a problem hiding this comment.
Can we just use the pattern synonym here?
| pure $ mkQualified_ (ByModuleName mn) a | |
| pure $ Qualified (ByModuleName mn) a |
There was a problem hiding this comment.
(and in a lot of other places)
There was a problem hiding this comment.
Weird because I thought I have already done that, maybe it was a different branch..
| newtype PSString = PSString { unPSString :: [Word16] } | ||
| deriving (Eq, NFData, Generic) | ||
| deriving newtype Hashable | ||
|
|
||
| instance NFData PSString | ||
| instance Serialise PSString | ||
| instance Ord PSString where | ||
| compare (PSString a) (PSString b) = compare a b | ||
|
|
||
| instance Show PSString where | ||
| show = show . codePoints | ||
|
|
||
| toUTF16CodeUnits :: PSString -> [Word16] | ||
| toUTF16CodeUnits (PSString ps) = ps | ||
|
|
||
| mkPSString :: [Word16] -> PSString | ||
| mkPSString = PSString | ||
|
|
||
|
|
||
| instance Semigroup PSString where | ||
| PSString a <> PSString b = PSString (a <> b) | ||
|
|
||
| instance Monoid PSString where | ||
| mempty = PSString [] | ||
| mappend = (<>) | ||
|
|
||
| instance Codec.Serialise PSString where | ||
| encode (PSString s) = Codec.encode s | ||
| decode = mkPSString <$> Codec.decode | ||
|
|
||
|
|
There was a problem hiding this comment.
I assume these changes are preparation for also interning PSString?
There was a problem hiding this comment.
You are correct, this is a leftover from interning. I reverted it but didn't revert the changes.
| decode = ProperName . hashCons <$> decode | ||
|
|
||
| instance Ord (ProperName a) where | ||
| compare (ProperName a) (ProperName b) = compare (unHashCons a) (unHashCons b) |
There was a problem hiding this comment.
Same with ModuleName, why can't we use HashCons' Ord?
Cleaned up.