Conversation
Polymorphic ModuleT type: when parsing foreign declarations we don't have access to their type, and thus we need a `ModuleT ()` type. The original `Module` type becomes an alias for `ModuleT Type`.
It is required when runnings `moduleToJs`.
|
I think this is ready for a review. |
|
I'm wondering if we should add a Also, @joneshf, do you have suggestions for the corefn JSON format, since we should break them here (or in a separate PR, but before 0.12)? |
|
I'd suggest a separate PR. I don't really know what's happening here and I don't want to do a drive-by on this. I put some comments in the other PR |
|
This adds
This allows to pick up CoreFn from its json rep and turn it into javascript code. |
|
|
- change the json representation of CoreFn - store module name on the module object - `buildMakeAction`: output single module json object, rather an object with a single key (module name) pointing to module json object.
- read the new json CoreFn representation - extend tests so that all the CoreFn structures are tested.
- `moduleToJSON`: include module comments inside `comments` field. - `moduleFromJSON` - add tests
|
I run the zephyr's test suite which compiles quite a few libraries. So the new json representation seems to work quite fine. Maybe some things could be named better or represented in a better way. |
joneshf
left a comment
There was a problem hiding this comment.
Thanks so much for making these changes! I think it looks great!
| literalToJSON t (ArrayLiteral xs) = toJSON ("ArrayLiteral", map t xs) | ||
| literalToJSON t (ObjectLiteral xs) = toJSON ("ObjectLiteral", recordToJSON t xs) | ||
| literalToJSON _ (NumericLiteral (Left n)) | ||
| = object |
There was a problem hiding this comment.
I don't think you need to go through and replace all of this now, but there's an alternative approach which skips over creating the intermediate data structure: https://hackage.haskell.org/package/aeson-1.2.1.0/docs/Data-Aeson.html#g:7
You'd change expressions from
object
[ T.pack "foo" .= foo
, T.pack "bar" .= bar
]to expressions like
pairs
( T.pack "foo" .= foo
<> T.pack "bar" .= bar
)It's supposedly faster and uses less memory. So given that the json blobs have gotten bigger, it might be a change that makes sense.
There was a problem hiding this comment.
@joneshf I think we'd need to add ToJSON instances to make it work (since the right hand side of .= expects an instance of ToJSON. This is a bit more work so I'd like to leave it for later.
There was a problem hiding this comment.
You could just encode to Value on the right-hand-side which picks the trivial ToJSON instance.
There was a problem hiding this comment.
@kritzcreek you're right, but let's do that in another PR.
| , T.pack "foreign" .= map (identToJSON . fst) (moduleForeign m) | ||
| , T.pack "decls" .= map bindToJSON (moduleDecls m) | ||
| , T.pack "builtWith" .= toJSON (showVersion v) | ||
| , T.pack "comments" .= map toJSON (moduleComments m) |
|
I am very happy with this. 👍 |
|
I have more, experimenting in zephyr. I'd like to add type annotations to corefn, would that be fine? (but this can be in another PR). |
|
Yeah, that's fine, if they're available. I'd like to use them in my Go backend after finishing the purescript-purescript-compiler-backend-utils library. But I don't need them per se (can use |
|
I'm a little worried about the size of the generated JSON. Part of the reason for the unconventional format before was that I wanted to reduce the size and keep the output somewhat human-readable. Could you please see how many lines are generated for a bigger file? Maybe something like Thermite's main module? 4000+ lines for |
|
@coot Could you please try moving the source file info to the top level? |
|
Was it not possible to just change the JSON renderer for |
|
I think it was, if you prefer that I'll update the PR. The only reason for having it exposed on the corefn module, is for tooling that might use it - if it's written in haskell and one would liket use the comipler |
|
Looking forward to a more complete (incl types) JSON dump-corefn format! Can't wait for this to land, will it be in 0.12? (The old |
|
I didn’t start working on the go backend, I want to wait for the new corefn dump to be merged and released. 😆
It will probably be similar to my Python backend https://github.com/rightfold/pegasus
Sent from my iPhone.
… Op 25 sep. 2017 om 16:10 heeft Phil Schumann ***@***.***> het volgende geschreven:
Can't wait for this to land, will it be in 0.12? (The old --dump-imperative-core would be great too but seems it's been postponed) Not sure why anyone cares about the file size of an intermediate format to be further machine-processed. @rightfold where's your "Go backend" to be found? I was just about to embark on exactly such hackery, but if it's FOSS I'd rather contribute to yours
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
The latest commit in this PR from 2 weeks ago doesn't build at my end, anything I'm missing? stack is up to date. Well it passed your CI so the prob must be at my end, but I've applied all changes to a fresh unmodified fork of the current purescript/purescript master.. Just tried to begin using this new |
|
@metaleap I merged master. It should be compile now for you. Try this branch rather than applying a patch to master. |
|
That was the ticket for me to build at my end, thanks, now I can begin toying with this =) |
| , moduleImports :: [(a, ModuleName)] | ||
| , moduleExports :: [Ident] | ||
| , moduleForeign :: [ForeignDecl] | ||
| , moduleForeign :: [ForeignDeclT t] |
There was a problem hiding this comment.
Could you please add a comment explaining why this type argument is needed?
|
@coot @rightfold @joneshf @kritzcreek @natefaubion Any more comments or shall I merge this now? |
paf31
left a comment
There was a problem hiding this comment.
Looks great to me! Thanks for all of the work on this.
|
My pleasure! |
kritzcreek
left a comment
There was a problem hiding this comment.
Looks great, I made a few comments, but they are all optional suggestions.
| case t of | ||
| "ProductType" -> return ProductType | ||
| "SumType" -> return SumType | ||
| _ -> fail ("not regonized ConstructorType: " ++ T.unpack t) |
| bindFromObj o = do | ||
| type_ <- o .: "bindType" :: Parser Text | ||
| case type_ of | ||
| "NonRec" -> (uncurry . uncurry $ NonRec) <$> bindFromObj' o |
There was a problem hiding this comment.
(uncurry . uncurry) NonRec
Would be a little less noisy
| literalToJSON t (ArrayLiteral xs) = toJSON ("ArrayLiteral", map t xs) | ||
| literalToJSON t (ObjectLiteral xs) = toJSON ("ObjectLiteral", recordToJSON t xs) | ||
| literalToJSON _ (NumericLiteral (Left n)) | ||
| = object |
There was a problem hiding this comment.
You could just encode to Value on the right-hand-side which picks the trivial ToJSON instance.
| -- The CoreFn module representation | ||
| -- | ||
| -- The json CoreFn representation does not contain type information. When | ||
| -- parsing it one gets back `ModuleT () Ann` rathern than `ModuleT Type Ann`, |
| -- | | ||
| -- The CoreFn module representation | ||
| -- | ||
| -- The json CoreFn representation does not contain type information. When |
There was a problem hiding this comment.
It looks like we don't even use the types in moduleForeign. If that's the case, I'd actually rather just get rid of the types completely and lose the type argument.
There was a problem hiding this comment.
As long as they're kept around in externs, don't drop them there! (Just chiming in as I'm wrestling with an alternative backend not targeting a dynamic/untyped language like JS/Py/Erl etc ... from what I can tell I'll have to reconstruct a lot from literals & externs & such as I'm working off CoreImp that I dump from the final rawJS --- to get all the optimizations and the basic fn-to-imp transforms.) Just a quick reminder to not forget the awesome use-case for alternative backends, some of which may want to keep around as much type info as possible, to minimize usage of boxed-variants (ie what is object in Java or interface{} in Go, etc) being passed around.
In my fork I experimentally added all Anns to your --dump-corefn module, to see what I can get beyond what's in externs. Not that much more but last I checked, it did have a bit more detail. A bit exploratory all right now, to write a backend based on --dump-corefoo outputs rather than right in Haskell in the fork, but it's fun for now. All right I'm done blogging & derailing the thread 😀
There was a problem hiding this comment.
As far as I can tell, we don't have any type information in the generated JSON right now.
|
This is great! I'm with it. |
|
Let's merge this and fix up any remaining issues in |
* CoreFn.FromJSON: parse json representation of CoreFn * CoreFn.Module: ModuleT Polymorphic ModuleT type: when parsing foreign declarations we don't have access to their type, and thus we need a `ModuleT ()` type. The original `Module` type becomes an alias for `ModuleT Type`. * Language.PureScript.CoreFn.DCE module * CoreFn: include `SourceSpan`s in json representation * CoreFn: add Meta to json representation It is required when runnings `moduleToJs`. * Update TestCoreFn * Change json encoding of CoreFn Bind * Remove `purs dce` command. * Remove CoreFN.DCE module * clean * remove white space in TestCoreFn * Object CoreFn representation. * CoreFn moduleToJSON: new representation - change the json representation of CoreFn - store module name on the module object - `buildMakeAction`: output single module json object, rather an object with a single key (module name) pointing to module json object. * CoreFn.FromJSON: update `moduleFromJson` - read the new json CoreFn representation - extend tests so that all the CoreFn structures are tested. * Add Module Comments to json CoreFn representation - `moduleToJSON`: include module comments inside `comments` field. - `moduleFromJSON` - add tests * CoreFn json repr: modulePath to the top level * Applied @paf31 & @kritzcreek review
I was just wondering if it was possible to use |
|
I think that `--dump-corefn` shouldn't generate javascript at all.
…On 20:11 Sun 22 Oct , Paul Young wrote:
#3049 (comment)
> I'm wondering if we should add a `purs codegen` command, which runs the JS codegen on a corefn file.
I was just wondering if it was possible to use `--dump-corefn` without producing JavaScript.
--
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub:
#3049 (comment)
|
Modify corefn json representation in a way to be able reproduce
CoreFnfrom it.