-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Nix: Add a tool for checking Haskell imports and exports #1768
Conversation
That's really cool! Some ideas we can use this for:
WDYT? |
Those are great use cases! Thinking a bit about the best way to implement them, it will probably be easier to express them directly in Haskell instead of fiddling with the dump using nix/bash/python etc. We could even build a small tool around this with optparse-applicative:
Where
This would help getting the module names right based on the filenames (as the module declaration is not included in the ddump, for example) The nix/haskellimports/Main.hs would grow a bit, but it should be low maintenance and simplify everything else a lot. Does that make sense? |
Yes. Sounds better than dumping, reloading the file in python etc.
Personally, I like CSV more here. I can load this directly into Calc/Excel and play around.
Not sure if that's possible with |
Still work in progress, but the basic idea works: [nix-shell]$ hsie check-aliases --src src
The following imports have inconsistent aliases:
Module 'Data.ByteString' has the aliases:
'B' in file:
src/PostgREST/Config.hs
'BS' in file:
src/PostgREST/ApiRequest.hs
src/PostgREST/Types.hs
Module 'Data.ByteString.Char8' has the aliases:
'BS' in files:
src/PostgREST/Config.hs
src/PostgREST/Middleware.hs
src/PostgREST/Private/QueryFragment.hs
src/PostgREST/QueryBuilder.hs
src/PostgREST/RangeQuery.hs
src/PostgREST/Statements.hs
'BS8' in file:
src/PostgREST/App.hs
Module 'Data.ByteString.Lazy' has the aliases:
'BL' in files:
src/PostgREST/ApiRequest.hs
src/PostgREST/Private/QueryFragment.hs
src/PostgREST/Types.hs
'LBS' in file:
src/PostgREST/App.hs
src/PostgREST/OpenAPI.hs
Module 'Data.HashMap.Strict' has the aliases:
'HM' in file:
src/PostgREST/Private/QueryFragment.hs
'HashMap' in file:
src/PostgREST/OpenAPI.hs
'M' in files:
src/PostgREST/ApiRequest.hs
src/PostgREST/Auth.hs
src/PostgREST/DbRequestBuilder.hs
src/PostgREST/DbStructure.hs
src/PostgREST/Middleware.hs
src/PostgREST/Parsers.hs
src/PostgREST/Types.hs
Module 'Data.Set' has the aliases:
'S' in files:
src/PostgREST/ApiRequest.hs
src/PostgREST/DbRequestBuilder.hs
src/PostgREST/DbStructure.hs
src/PostgREST/Parsers.hs
src/PostgREST/QueryBuilder.hs
src/PostgREST/Types.hs
'Set' in file:
src/PostgREST/App.hs
Module 'Hasql.DynamicStatements.Snippet' has the aliases:
'H' in files:
src/PostgREST/Private/Common.hs
src/PostgREST/Private/QueryFragment.hs
src/PostgREST/QueryBuilder.hs
src/PostgREST/Statements.hs
'SQL' in file:
src/PostgREST/App.hs
Module 'Hasql.Pool' has the aliases:
'P' in file:
src/PostgREST/Error.hs
'SQL' in file:
src/PostgREST/App.hs
Module 'Hasql.Transaction' has the aliases:
'H' in file:
src/PostgREST/Middleware.hs
'HT' in file:
src/PostgREST/DbStructure.hs
'SQL' in file:
src/PostgREST/App.hs
Module 'Network.HTTP.Types.Status' has the aliases:
'HT' in file:
src/PostgREST/Error.hs
'HTTP' in file:
src/PostgREST/App.hs
|
Current outputs from |
We get both! The
That's extremely tricky, as we would need to run the whole compiler machinery, compile all dependencies etc. I'll add a bash wrapper script that provides the |
Just skimmed through the source code: It doesn't look like the exit code is any different for |
Yes, great idea! Added. Also added
Nearly done with this :-) |
Left for later PRs:
|
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 didn't have the chance, yet, to actually run the tools, but will do so soon.
Doing the review, I will admit that I didn't go through the meat of the hsie functions in detail. The code looks very organized and well readable, though.
I thought briefly about possibly renaming the dump
command, because I was initially a bit confused when reading the part about dump-minimal-imports
. But dump
is probably the best way to describe it...
Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
Many thanks for your review @wolfgangwalther !
Maybe |
I don't think I would have been less confused. But if we plan to have While trying the tools (see below), I thought about this a bit more and I think I now know where my confusion is coming from. When we look at everything that is done with
This will also be important later on, when you want to analyze exports - because you actually don't care about imports but usage of those. I don't think it ever makes sense to dump imports ( hsie dump-imports main src
hsie dump-exports main src
hsie dump-usage usage # assume --ddump-minimal-imports is saved in "usage" Passing the folders to work on as arguments also avoids the ambiguity between This takes away the possibility of running the I just tried the tools and noted the following:
|
It should be useful e.g. when we analyze exports - we need the full internal imports from ddump-minimal-imports, and the exports from the actual source code. To graph the full symbol imports, we also need ddump-minimal-imports. But agree that having
We need it to display the file that issues are found in, e.g. with
Great idea, and needed anyway e.g. for the graphing commands. Added.
Yes, much better! That's one up from what our GHC friends came up with ( |
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.
Just tried check-wildcards
and it gives me an error:
$ hsie check-wildcards --ok Protolude src main
option --ok: cannot parse value `Protolude'
Usage: hsie check-wildcards [-o|--ok OKMODULE]
Check that no unwanted modules are imported as wildcards
Just noting for now:
There is also a reverse approach for check-aliases
. Some aliases are used for different modules in different files. Example:
file | import | alias |
---|---|---|
PostgREST.Config | Data.Configurator | C |
Main | Hasql.Connection | C |
This is probably not something that we can auto-detect easily, because there could be lots of false-positives, too. Think the different Hasql packages - could all be imported with SQL.
.
Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
Co-authored-by: Wolfgang Walther <wolfgangwalther@users.noreply.github.com>
Good catch - not sure when that broke. Fixed! We're reaching a point where we need a test suite, might be worth to spin this off at some point. |
Many thanks for your review @wolfgangwalther ! |
This uses the actual GHC parser, so it should be fairly robust. Works on both our Haskell modules and the ones generated with
-ddump-minmal-imports
.To use:
Example output so far:
Example usage in nix/devtools.nix, WIP.
@wolfgangwalther : This might be useful for many automated checks and analysis on our imports. Any comments or ideas?