Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

lf-
Copy link
Contributor

@lf- lf- commented Feb 12, 2025

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:

  • Documented new APIs with Haddock markup
  • Added @since declarations to the Haddock
  • Ran stylish-haskell on any changed files.
  • Adhered to the code style (see the .editorconfig file for details)

After submitting your PR:

  • Update the Changelog.md file with a link to your PR
  • Bumped the version number if there isn't an (unreleased) on the Changelog
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts)

@lf-
Copy link
Contributor Author

lf- commented Feb 12, 2025

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.

lf- added 3 commits February 11, 2025 16:49
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.
@lf- lf- force-pushed the jade/entitydef-location branch from e917484 to 0aa83dd Compare February 12, 2025 00:49
Copy link
Collaborator

@parsonsmatt parsonsmatt left a 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

Comment on lines +5 to +7
* [#1569](https://github.com/yesodweb/persistent/pull/1569)
* Version bounds for Persistent 2.15.0.0, also synchronize version
number with `persistent`.
Copy link
Collaborator

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

@@ -279,7 +281,7 @@ embedEntityDefsMap existingEnts rawEnts =
-- instead of @['EntityDef']@.
--
-- @since 2.5.3
parseReferences :: PersistSettings -> Text -> Q Exp
parseReferences :: PersistSettings -> [(Maybe SourceLoc, Text)] -> Q Exp
Copy link
Collaborator

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.

Comment on lines +126 to +142
-- | A pair of (start line/col, end line/col) coordinates. The end column will
-- be one past the final character (i.e. the span (1,1)->(1,1) is zero
-- characters long).
--
-- Spans are 1-indexed in both lines and columns.
--
-- Conceptually identical to GHC's @RealSourceSpan@.
--
-- @since 2.15.0.0
data Span = Span
{ spanFile :: !Text
, spanStartLine :: !Int
, spanStartCol :: !Int
, spanEndLine :: !Int
, spanEndCol :: !Int
}
deriving (Show, Eq, Read, Ord, Lift)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd prefer to avoid growing this module any further - any way we can put this somewhere else?

Comment on lines +176 to +178
, entitySpan :: !(Maybe Span)
-- ^ Source code span occupied by this entity. May be absent if it is not
-- known.
Copy link
Collaborator

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

@@ -157,7 +157,7 @@ test-suite test
hs-source-dirs:
test/

ghc-options: -Wall
ghc-options: -Wall -Wno-incomplete-uni-patterns -dth-dec-file
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's -dth-dec-file do?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that's a mistake! shouldn't be in there. however you can consult the blog post from when i had the terrible misfortune to be debugging persistent's quasiquoter in my first or second month learning haskell; it might actually be useful tips. https://jade.fyi/blog/debugging-template-haskell/

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohhh that's super cool! Thanks for the reference 😄

(full circle: i wrote the bug you diagnosed 😂)

Comment on lines +82 to +83
personDefBeforeLoc :: SourceLoc
personDefBeforeLoc = $(TH.lift @_ @SourceLoc . sourceLocFromTHLoc =<< TH.location)
Copy link
Collaborator

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

@@ -76,7 +76,7 @@ library
, monad-logger >= 0.3.25
, mtl
, path-pieces >= 0.2
, persistent >= 2.14 && < 2.15
, persistent >= 2.15 && < 2.16
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since there are no source changes, we can probably just do

Suggested change
, persistent >= 2.15 && < 2.16
, persistent >= 2.14 && < 2.16

@parsonsmatt
Copy link
Collaborator

Build failure is due to persistent-th's benchmark looks like

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.

Include source file information when parsing UnboundEntityDef
2 participants