Skip to content

Warn about used unlisted modules - #1455

Closed
sebastiaanvisser wants to merge 11 commits into
haskell:masterfrom
sebastiaanvisser:warn-about-used-unlisted-modules
Closed

sebastiaanvisser wants to merge 11 commits into
haskell:masterfrom
sebastiaanvisser:warn-about-used-unlisted-modules

Conversation

@sebastiaanvisser

Copy link
Copy Markdown

(After some discussions with @dcoutts at Zurihac2013)

Two small contributions:

  1. Invoke GHC using the -M flag to create a makefile containing module dependencies. The simple makefile format is parsed into a ModuleHierarchy datatype which is (for now) a simple mapping from modules to their dependencies.
  2. Diff the module dependencies fetched from GHC with the modules listed in the .cabal file. For all unlisted module we produce a warning so users are encouraged to add the modules.

Currently the module dependencies are not stored anywhere, however this might be a useful thing to do in the future if more parts of the build process require it.

GHC might fail on the -M flag in the case of cyclic dependencies. I don't want to disallow building programs with cyclic dependencies so we catch all errors in warn in the case of failure. Of course, we do continue the normal build process.

Let me know if anything is missing or things could be clearer. Thanks!

@tibbe

tibbe commented Aug 31, 2013

Copy link
Copy Markdown
Contributor

LGTM

@dcoutts do you also want to take a look?

Comment thread Cabal/Cabal.cabal Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should move this under Distribution.Simple, as that's where all the build system stuff lives.

In fact, it's completely ghc-specific at the moment (in principle the type is generic but the parsing is ghc-specific) so perhaps Distribution.Simple.GHC.ModuleDependencies is the right location.

@dcoutts

dcoutts commented Aug 31, 2013

Copy link
Copy Markdown
Contributor

So yes, I think it looks good. Just want to change where the module lives and that's it.

@sebastiaanvisser

Copy link
Copy Markdown
Author

Sounds good. Fixed.

@dcoutts

dcoutts commented Sep 2, 2013

Copy link
Copy Markdown
Contributor

Great.

Also just realised that this does it just for libs, not for exes. @sebastiaanvisser if you want to add that then great, if you don't have the time then I'll do it.

@tibbe this isn't essential for the 1.18.0.0 release because we can include it in a 1.18.1.x because it only adds to the API, doesn't change it. So we can put it in straight after the immediate release and gather a bit more testing. OTOH, I wouldn't object to it going in.

@23Skidoo

23Skidoo commented Sep 3, 2013

Copy link
Copy Markdown
Member

Do we really want to do this on every cabal build? I'm worried about compile times - running cabal build when nothing has changed already takes too much time IMO. Perhaps doing this check during cabal configure or cabal sdist would be better? Remember that we have to reconfigure anyway each time the .cabal file is changed.

@tibbe

tibbe commented Sep 3, 2013

Copy link
Copy Markdown
Contributor

I voted for during sdist.

@dcoutts

dcoutts commented Sep 20, 2013

Copy link
Copy Markdown
Contributor

I vote for every build, but lets see how expensive it really is first.

@cartazio

Copy link
Copy Markdown
Contributor

does this also cover files that are in tree, but unlisted in the cabal file?
eg .h / .c files?

@sebastiaanvisser

Copy link
Copy Markdown
Author

@dcoutts I'll make sure to also do this for executables and not only libraries.

@tibbe I'll will try to do some profiling for some smaller and some larger projects. I suspect not much overhead in general.

@23Skidoo ohter-modules are also included by using the libModules helper.

@cartazio No it doesn't cover all the files in the tree. It only covers unlisted Haskell modules that are (direct or indirectly) imported by listed dependencies.

@sebastiaanvisser

Copy link
Copy Markdown
Author

Checking for unlisted modules is now also done for executables. Before the check is done the Main module and the auto-generated Paths_xxx module are included as implicitly listed to prevent useless warnings.

Any more modules that need special treatment?

@sebastiaanvisser

Copy link
Copy Markdown
Author

Some simple profiling results

A no-op build simulating development in which we expect the most overhead. The patch makes the build slightly slower, but barely noticeable.

cabal build of executable with 6 modules

  5 runs WITH the patch included:
  ./prof  11.82s user 0.84s system 99% cpu 12.680 total
  5 runs WITHOUT the patch:
  ./prof  11.19s user 0.76s system 99% cpu 12.062 total

A larger install in which we expect the overhead to be negligible. The version of the patch is actually slightly faster, which is probably just noise.

cabal clean && cabal install of executable of with 6 modules

  5 runs WITH the patch included:
  ./prof  159.18s user 9.86s system 94% cpu 2:58.74 total
  5 runs WITHOUT the patch:
  ./prof  155.53s user 9.51s system 96% cpu 2:51.45 total

@tibbe

tibbe commented Sep 23, 2013

Copy link
Copy Markdown
Contributor

A 2-3% overhead seems OK to me.

@23Skidoo

Copy link
Copy Markdown
Member

@sebastiaanvisser

Can you measure the overhead on a larger program, such as darcs or agda? Also, I'd expect the overhead to be closer to 100% for incremental builds (running cabal build when nothing has changed). Incremental builds are already too slow, though, so perhaps we can solve this problem in a different way.

@sebastiaanvisser

Copy link
Copy Markdown
Author

A incremental cabal build of Agda for me slows down from 13.97s to 16.25s.

@tibbe

tibbe commented Oct 11, 2013

Copy link
Copy Markdown
Contributor

@sebastiaanvisser That's quite a lot, especially for an incremental build. I think we should only do this on sdist and check then.

@dcoutts

dcoutts commented Oct 17, 2013

Copy link
Copy Markdown
Contributor

Hmm, this is a bit disappointing. Note that check & sdist currently don't do any build so that's not going to be easy.

I wonder if we can't do better with the ghc -M approach to make it more incremental. For example could we do it on a per-file basis to discover direct deps only, and so then we only have to do that when the file changes.

Indeed if we peruse the approach of finding (& caching) the build graph ourselves then we could make incremental builds where nothing changes really quick (ie by not delegating to ghc --make at all).

@23Skidoo

Copy link
Copy Markdown
Member

Alternatively, we could use GHC API and write a small wrapper for ghc --make to make it dump the dependency graph before building (thus combining ghc --make and ghc -M invocations). The overhead would likely be lower.

@dcoutts

dcoutts commented Oct 20, 2013

Copy link
Copy Markdown
Contributor

Can we just add a check so that it's not re-generated if nothing has changed? Or are we worrying about the case where one file has changed? What are you calling an incremental build here?

If we do the ghc -M approach and we don't use ghc --make then we ought to be able to avoid the overhead of doing the full module scan twice.

@tibbe

tibbe commented Nov 11, 2013

Copy link
Copy Markdown
Contributor

What's the status of this pull request?

@sebastiaanvisser

Copy link
Copy Markdown
Author

I'm using this patch now for a while now and I'm am very happy with it. It prevented me from deploying broken packages to our local Hackage server a few times now, which feels like a win. A side effect of the patch is that it also warns about non-existing modules in your .cabal file, which allowed us to clean up some of them.

The performance issues are not at all a problem for any of our personal uses cases. I don't care about no-op builds for package containing 250 modules. It's just unnoticeable in real life. I do understand that some other Cabal users might notice a performance difference when user very large packages.

I'm not planning on changing it to work on check/sdist, I don't have the time to do it now and I don't have enough knowledge about the inner workings of Cabal to find a proper architecture.

It's up to you guys.

@tibbe

tibbe commented Nov 11, 2013

Copy link
Copy Markdown
Contributor

@sebastiaanvisser Thanks for the update. I will go ahead and close the pull request then, as I want to only want to keep active pull requests open, to avoid us missing any due to the sheer number of open ones*. The pull request will still be there if someone wants to pick it up in the future.

** We have the problem with our issue list right now, which is too big to be very useful anymore.

@tibbe tibbe closed this Nov 11, 2013
@23Skidoo

Copy link
Copy Markdown
Member

@tibbe We discussed this with @dcoutts in the context of parallel install. We want to modify ghc --make to output a dependency graph before building - this way, the sources will only be parsed once and there should be no performance difference for large projects. Caching the dependency graph should also allow us to speed-up incremental builds.

Related: #1562 (we can output the set of extensions used by the program together with the build graph).

@nh2

nh2 commented Jun 5, 2014

Copy link
Copy Markdown
Member

@23Skidoo Is there already a GHC ticket for your efforts?

@23Skidoo

23Skidoo commented Jun 5, 2014

Copy link
Copy Markdown
Member

@nh2 I haven't had time to finish this, but I plan to do it this summer.

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.

6 participants