Option --dump-coreimp to output imperative-core to JSON#3097
Conversation
src/Language/PureScript/Make.hs
Outdated
| coreFnFile = outputDir </> filePath </> "corefn.json" | ||
| min3 js exts coreFn | ||
| coreImpFile = outputDir </> filePath </> "coreimp.json" | ||
| min3 js exts coreFn coreImp |
| T.pack name .= map astToJSON asts | ||
| ] | ||
|
|
||
| subASTsLeftRightToJSON :: String -> (Maybe SourceSpan) -> AST -> AST -> Value |
There was a problem hiding this comment.
Don't need the parens around Maybe SourceSpan
There was a problem hiding this comment.
All 3 occurrences removed with last added commit
|
|
||
| subASTSingleToJSON :: String -> (Maybe SourceSpan) -> AST -> Value | ||
| subASTSingleToJSON name maybeSrcSpan ast = | ||
| object [T.pack "sourceSpan" .= toJSON maybeSrcSpan, |
There was a problem hiding this comment.
Does this hit the same issue as the CoreFn change, where it stores the file path in every node?
There was a problem hiding this comment.
Well with --source-maps enabled. Is it an issue to begin with? We're emitting sizable to-be-machine-processed json files already.. I can certainly ditch the file path if you guys prefer, personally am hoping I won't need the sourcemappings for my ps2go transpiler anyway
… their JSON decoding
…-perhaps-most coreimp-based codegen/tooling use-cases and all others can easily ignore it
…ent corefn as-is)
|
|
||
| moduleToJSON :: (Show a) => Version -> Module a -> [AST] -> Value | ||
| moduleToJSON v m a = object [ T.pack "body" .= map (astToJSON) a | ||
| , T.pack "corefn" .= CoreFnToJSON.moduleToJSON v m -- might be good to "keep a snapshot of the original FP logic of the module" depending on coreimp-processing use-case (others can ignore it) |
There was a problem hiding this comment.
I don't know how I feel about including the functional core here. What's the use case?
There was a problem hiding this comment.
Ultimately I want to push (later) for an argument "include-everything-you-know-incl-especially-type/ctor-infos" to CoreFn.ToJSON.moduleToJSON. I get that the existing --dump-corefn output is meant to be small and semi-readable for (typically) troubleshooting use-cases, but for the --dump-coreimp I see the use-cases as tools that need the most information possible about the original source. More in-depth type info (ADTs / records) in the current (JS-focused) CoreImp will be very hard to reconstruct from these "untyped" (other than stringlit/boollit/numlit/obj-lit) --- including a more detailed corefn (than the original/current --dump-corefn scenario envisions) right there in the coreimp dump will probably help. I guess for now that's too vague to let into the main repo so I'll take it out for now in the next commit, then keep tinkering locally until it all solidifies a bit more.
| moduleToJSON :: (Show a) => Version -> Module a -> [AST] -> Value | ||
| moduleToJSON v m a = object [ T.pack "body" .= map (astToJSON) a | ||
| , T.pack "corefn" .= CoreFnToJSON.moduleToJSON v m -- might be good to "keep a snapshot of the original FP logic of the module" depending on coreimp-processing use-case (others can ignore it) | ||
| , T.pack "modraw" .= toJSON (show m) -- only way to capture type/ctors info without rewriting corefn, good enough for those needing it badly enough, others can ignore it |
There was a problem hiding this comment.
What does modraw mean? Also, let's not use show here.
In general, I'd like to keep this minimal. It's harder to remove features later.
There was a problem hiding this comment.
Yeah I'll do away with this shortly, accidentally pushed this last commit. Still a bit more in flux than I expected I'm afraid!
|
That last commit 5e9d1fc.. wasn't intended, what a mess, sorry |
New
purs compileoption--dump-coreimp, exactly like the existing--dump-corefn, to dump theCoreImpAST to acoreimp.jsonoutput file.Requested in #876 and also in #711 in the comments
(The results can be seen in the various
coreimp.jsonfiles throughout this directory --- one example )New modules:
src/Language/PureScript/CoreImp/ToJSON.hs--- modeled after the existingsrc/Language/PureScript/CoreFn/ToJSON.hs. (Has duplicated the trivial tiny helper functionsidentToJSONandmoduleNameToJSONas I didn't want to impress changes on to what the existing original exports.)Existing modules:
Merely duplications of the existing
--dump-corefnoption handling in:app/Command/Compile.hssrc/Language/PureScript/Make.hssrc/Language/PureScript/Options.hs(Too small & trivial to generalize into helper funcs for now IMHO --- until a 3rd
--dump-xyzrequest comes along in the future at least.)