-
Notifications
You must be signed in to change notification settings - Fork 6
Support new JSON format #42
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
Conversation
src/CoreFn/Expr.purs
Outdated
-- instance functorCaseAlternative :: Functor CaseAlternative where | ||
-- map f (CaseAlternative cabs car) = CaseAlternative | ||
-- (map (map f) cabs) | ||
-- (either (Left <<< map (map f *** map f)) (Right <<< map f) car) |
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 still need to figure out how to satisfy the Functor instances that this depends on.
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.
While that either
call is concise, I find it difficult to parse. A case
expression might be better if you plan on having less experienced contributors in the future.
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 don’t disagree but I tried to keep this port as close as possible to the Haskell version so that nothing was accidentally lost in translation.
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.
Got it. That explains the style. Thanks for the explanation and working on the port. It'll make adding backends easier in the future.
The tests include the JSON output from running diff --git a/tests/TestCoreFn.hs b/tests/TestCoreFn.hs
index 3f6972b1..5b0f0a79 100644
--- a/tests/TestCoreFn.hs
+++ b/tests/TestCoreFn.hs
@@ -12,6 +12,9 @@ import Data.Aeson
import Data.Aeson.Types
import Data.Version
+import Data.ByteString.Lazy.Char8
+import Debug.Trace
+
import Language.PureScript.AST.Literals
import Language.PureScript.AST.SourcePos
import Language.PureScript.Comments
@@ -34,7 +37,8 @@ parseModule = parse moduleFromJSON
parseMod :: Module Ann -> Result (Module Ann)
parseMod m =
let v = Version [0] []
- in snd <$> parseModule (moduleToJSON v m)
+ j = moduleToJSON v m
+ in snd <$> parseModule (trace (unpack (encode j)) j)
isSuccess :: Result a -> Bool
isSuccess (Success _) = True |
src/CoreFn/Expr.purs
Outdated
-- map f (CaseAlternative { caseAlternativeBinders, caseAlternativeResult }) = CaseAlternative | ||
-- { caseAlternativeBinders: (map (map f) caseAlternativeBinders) | ||
-- , caseAlternativeResult: (either (Left <<< map (map f *** map f)) (Right <<< map f) caseAlternativeResult) | ||
-- } |
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 think the last thing to do in this PR is to figure out why the Functor instances that are commented out don't work.
They're not actually used anywhere but it might be nice to have them.
This was taken from https://github.com/purescript/purescript/blob/c19a79285c5697b59c46803483b41ffeaa5cd7b0/src/Language/PureScript/CoreFn/Expr.hs#L89-L93
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 don't see a Functor instance for Expr
.
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.
The other instances are here:
purescript-corefn/src/CoreFn/Expr.purs
Line 65 in aa1d736
-- derive instance functorExpr :: Functor Expr |
purescript-corefn/src/CoreFn/Expr.purs
Line 117 in aa1d736
-- derive instance functorBind :: Functor Bind |
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.
This is the error:
[1/1 TypesDoNotUnify] src/CoreFn/Expr.purs:117:8
117 derive instance functorBind :: Functor Bind
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Could not match type
b1
with type
a2
while trying to match type Expr b1
with type Expr t0
while checking that expression (map (map $f146)) $v148
has type Tuple (Tuple t0 Ident) (Expr t0)
in value declaration functorBind
where b1 is a rigid type variable
a2 is a rigid type variable
t0 is an unknown type
https://travis-ci.org/paulyoung/purescript-corefn/jobs/345111990#L1549
I guess the issue might just be that Functor
can’t be derived, all though I’m not sure if there would be a more specific error if that was the case.
|
||
derive instance eqBind :: Eq a => Eq (Bind a) | ||
derive instance ordBind :: Ord a => Ord (Bind a) | ||
|
||
instance functorBindRec :: Functor Bind where | ||
map f (NonRec a i e) = NonRec (f a) i (map f e) | ||
map f (Rec ts) = Rec $ map (bimap (lmap f) (map f)) ts |
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.
@LiamGoodacre does this look right to you?
FWIW, stack build --ghc-options "-ddump-deriv"
produced .stack-work/dist/x86_64-osx/Cabal-2.0.0.2/build/src/Language/PureScript/CoreFn/Expr.dump-deriv
which contained this:
instance GHC.Base.Functor
Language.PureScript.CoreFn.Expr.Bind where
GHC.Base.fmap
f_amsj
(Language.PureScript.CoreFn.Expr.NonRec a1_amsk a2_amsl a3_amsm)
(Language.PureScript.CoreFn.Expr.NonRec a1_amsk a2_amsl a3_amsm)
= Language.PureScript.CoreFn.Expr.NonRec
(f_amsj a1_amsk)
((\ b1_amsn -> b1_amsn) a2_amsl)
(GHC.Base.fmap f_amsj a3_amsm)
GHC.Base.fmap f_amso (Language.PureScript.CoreFn.Expr.Rec a1_amsp)
= Language.PureScript.CoreFn.Expr.Rec
(GHC.Base.fmap
(\ b3_amsq
-> case b3_amsq of {
((,) a1_amsr a2_amss)
-> (,)
((\ b2_amst
-> case b2_amst of {
((,) a1_amsu a2_amsv)
-> (,) (f_amso a1_amsu) ((\ b1_amsw -> b1_amsw) a2_amsv) })
a1_amsr)
(GHC.Base.fmap f_amso a2_amss) })
a1_amsp)
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.
Upon closer inspection I'm pretty confident that this is equivalent.
-- | | ||
-- A generated name used only for type-checking | ||
-- | ||
| UnusedIdent |
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'm not sure whether to keep this or not. There's nothing that can be code-generated from it, but the case needs to be handled or unsafePartial
used.
I'm seeing 2 issues with converting corefn.json files that are produced with I'm looking into whether this is an issue with my conversion or the original Haskell version. |
Actually, everything is fine. Some modules in the output directory were old and using the old format. |
src/CoreFn/FromJSON.purs
Outdated
>>= readArray | ||
>>= traverse identFromJSON | ||
|
||
moduleDecls <- pure [] |
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.
Whoops
src/CoreFn/FromJSON.purs
Outdated
type_ <- readProp "metaType" json >>= readString | ||
case type_ of | ||
"IsConstructor" -> isConstructorFromJSON json | ||
"IsNewType" -> pure IsNewtype |
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.
The test failing here might be because of the casing. Probably needs to be "IsNewtype"
.
Should close #41.
This is a port of FromJSON.hs.
I still need to port TestCoreFn.hs.