Skip to content

Track where clause metadata#3317

Merged
garyb merged 5 commits intopurescript:masterfrom
joneshf:3297-fix
Apr 24, 2018
Merged

Track where clause metadata#3317
garyb merged 5 commits intopurescript:masterfrom
joneshf:3297-fix

Conversation

@joneshf
Copy link
Copy Markdown
Member

@joneshf joneshf commented Apr 23, 2018

Re: #3297

Opening this PR to get some feedback on this approach.

  • I'm not at all attached to the names. If we'd prefer different names, I have no problem replacing them.
  • I added some metadata to the CoreFn stuff. I think I got all the places, but might have missed something. Is this the right idea? Is that the right way to do it if so?
  • I couldn't get the tests to run, so this branch will almost surely fail on CI. There's some conflict with purescript-foldable-traversable. Since the changes in this branch are unrelated, I'm assuming it's known and can merge in a fix to this branch once it's on master.
  • Looking at the contribution guidelines, it recommends adding a test to the examples. What test can I write there? It feels like the useful test would be that let bindings and where clauses gets parsed with the correct metadata. Should we eschew another test in the examples in favor of that? Or, is this a hard rule?
  • Did I miss anything?

joneshf added 2 commits April 23, 2018 08:38
When we parsed where clauses, we desugared directly to a let binding.
When we did that desugaring,
we lost the information about whether a let binding was ever a where clause.

We add a bit of metadata to the let bindings we generate
so we can track whether it began its life as a where clause or not.

This is already showing to be directly useful,
as we can pretty print where clauses!
Should allow external tools to also benefit from the metadata.
Although not explicitly required for tracking where clauses,
this seems beneficial to have in the CoreFn.
It should help external tools track where clauses.

Also, we already had the metadata.
Why not pass it along?
Copy link
Copy Markdown
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach seems reasonable to me, it's pretty conservative but gets the information you need - we can make a more drastic change at a later date if we decide to change the where semantics to be more like Haskell.

Tests, I think what we have will probably cover this already - I haven't checked, but I would have thought there's at least one passing test that uses a let and one that uses a where 😉

-- |
-- The let binding was always a let binding
--
| NotFromWhere
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FromLet perhaps? 😄

exprToCoreFn ss com ty (A.Let A.FromWhere ds v) =
Let (ss, com, ty, Just IsWhere) (concatMap declToCoreFn ds) (exprToCoreFn ss [] Nothing v)
exprToCoreFn ss com ty (A.Let A.NotFromWhere ds v) =
Let (ss, com, ty, Nothing) (concatMap declToCoreFn ds) (exprToCoreFn ss [] Nothing v)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these cases match apart from the metadata part, maybe could just move the conditional in there?

@garyb
Copy link
Copy Markdown
Member

garyb commented Apr 23, 2018

And yep, tests are known to fail right now, it's being worked on!

@LiamGoodacre
Copy link
Copy Markdown
Member

@joneshf if you rebase against master the tests should be passing again now that this is merged: #3312

@garyb
Copy link
Copy Markdown
Member

garyb commented Apr 24, 2018

Any further comments anyone, or should I merge this?

Copy link
Copy Markdown
Member

@LiamGoodacre LiamGoodacre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@garyb garyb merged commit 345f643 into purescript:master Apr 24, 2018
@garyb
Copy link
Copy Markdown
Member

garyb commented Apr 24, 2018

Thanks @joneshf 😄

@joneshf
Copy link
Copy Markdown
Member Author

joneshf commented Apr 24, 2018

Thank you all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants