-
Notifications
You must be signed in to change notification settings - Fork 301
Add position info to EntityDef #1569
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
Add position info to EntityDef #1569
Conversation
|
idk if i parsed the PVP correctly here, this might actually be non breaking so perhaps should be the C instead of B component, but it will blow up anyone using the internals of the quasiquoter/TH stuff. |
e917484 to
0aa83dd
Compare
parsonsmatt
left a comment
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.
nice! a couple suggestions. don't need to worry about the version bump on persistent-test, once we release I'll revise the Hackage page and/or we can do a patch version bump
persistent-test/ChangeLog.md
Outdated
| * [#1569](https://github.com/yesodweb/persistent/pull/1569) | ||
| * Version bounds for Persistent 2.15.0.0, also synchronize version | ||
| number with `persistent`. |
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.
We don't need to worry about this sync. If it's just version bounds then it can be a patch bump or even an (unreleased) and I'll make a revision on Hackage
persistent/Database/Persist/TH.hs
Outdated
| -- | ||
| -- @since 2.5.3 | ||
| parseReferences :: PersistSettings -> Text -> Q Exp | ||
| parseReferences :: PersistSettings -> [(Maybe SourceLoc, Text)] -> Q Exp |
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.
Ah, dang, this is listed as -- * Internal but is not itself part of an .Internal module. So this is a breaking change and we need 2.15 for this.
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.
oof! well i suppose i guessed right at least?
We probably should move it to a .Internal module though.
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.
Okay I just committed moving it. Feel free to review commit-by-commit and maybe clone locally and use git diff --color-moved if that's useful.
We can drop that commit if we want, it wasn't hard to write but it does prevent this happening in the future.
| , entitySpan :: !(Maybe Span) | ||
| -- ^ Source code span occupied by this entity. May be absent if it is not | ||
| -- known. |
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 guess we wouldn't have this if we skip the quasiquoter entirely and write the instances ourselves. Valid
| personDefBeforeLoc :: SourceLoc | ||
| personDefBeforeLoc = $(TH.lift @_ @SourceLoc . sourceLocFromTHLoc =<< TH.location) |
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 there may be a better way of doing this -
do
firstLoc <- [d| firstLocation = $(TH.location) |]
decls <- share [mkPersistWith sqlSettings ...] [persistUpperCase| ... |]
secondLoc <- [d| secondLocation = $(TH.location) |]
pure (concat [firstLoc, decls, secondLoc])This would require a little less spooky magic
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.
Part of the goofiness here is that there's no instance Lift TH.Loc. But you're right, I could extract this.
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.
Okay I give up. I don't think it is possible to do what you suggest. There's no instance Lift TH.Loc, and I believe that you get one value of TH.location per top level splice which means that in the proposed code, the before/after loc values are the same.
This also means it cannot be extracted. Bleh. TH is really hard.
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.
Ah good point. My apologies
It looks like this is failing on GHC 8.8 - complaining about TH.lift @_ @SourceLoc. My guess is that GHC 8.8 has only one type variable for lift
|
Build failure is due to |
0aa83dd to
87864c7
Compare
This is an initial implementation that we can API-compatibly improve in the future by providing more accurate information. However, to do that, we would have to rewrite the entity definition parser with e.g. megaparsec. This is a reasonable course of action but rewriting it is going to be more work and we can ship position info we could improve later with the existing parser.
It winds up making a lot more sense legibility wise to just move the entire module. Maybe the API could be shifted back later (but it uses a pile of internals that really are probably more bothersome to have in a different file?), but this is at least easiest to review since it is quite literally just copy pasting the entire content of the module.
87864c7 to
0f6dfdf
Compare
…ies/persistent into jade/entitydef-location
|
What is the intended replacement for |
|
Could you make an issue with your specific use case? In the meantime, you can depend on the internal module (it is exposed). The docs for it say you can define entities separately and then use that to make a migration. However, that shouldn't be necessary with the way |
Internal Mercury bug: DUX-3027
Fixes: #1567
This is an initial implementation that we can API-compatibly improve in
the future by providing more accurate information. However, to do that,
we would have to rewrite the entity definition parser with e.g.
megaparsec. This is a reasonable course of action but rewriting it is
going to be more work and we can ship position info we could improve
later with the existing parser.
Currently this gives users the entire file in which the model is defined, but not anything closer since the parser throws all that stuff out.
Before submitting your PR, check that you've:
@sincedeclarations to the Haddockstylish-haskellon any changed files..editorconfigfile for details)After submitting your PR:
(unreleased)on the Changelog