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

More recompilations than expected with variable rules #524

Closed
takano-akio opened this issue Mar 31, 2017 · 3 comments
Closed

More recompilations than expected with variable rules #524

takano-akio opened this issue Mar 31, 2017 · 3 comments

Comments

@takano-akio
Copy link
Contributor

I expect the following program to print "updated" just once, but with shake HEAD (but not with shake-0.15.11) it prints "updated" twice. This problem looks similar to #523 and may be related, but it is about more recompilations than expected, not less.

import Development.Shake

main :: IO ()
main = do
  writeFile "0.in" "foo"
  writeFile "1.in" "foo"
  run $ rules "0.out" -- prints "updated"
  writeFile "0.in" "bar"
  run $ rules "1.out" -- prints "updated" again
  where
    run r = do
      putStrLn "Running shake"
      shake shakeOptions r

rules :: FilePath -> Rules ()
rules wanted = do
  want ["top"]

  "0.out" %> \f -> do
    alwaysRerun
    writeFile' f =<< readFile' "0.in"
    liftIO $ putStrLn "updated"
  "1.out" %> \f -> writeFile' f =<< readFile' "1.in"

  phony "top" $ do
    -- alwaysRerun -- uncommenting this line fixes the issue
    need [wanted]

One suspicious point in this program is the rule for "top", whose content changes depending on the value of the argument wanted. I had thought this would be ok because it is a phony target, and thus merely defines an abbreviation. But perhaps I'm not supposed to do this?

@ndmitchell
Copy link
Owner

Thanks! I've pushed a potential fix to HEAD. I'll describe it in detail later (just rushing out), but you might want to retry the original problem you were having. Should fix both tickets.

@pacak
Copy link

pacak commented Apr 3, 2017

Nope, extra recompilations I showed logs for in #519 are still there with this fix applied.

@ndmitchell
Copy link
Owner

So the issue that I fixed is that as part of #427 I moved checking whether the output was dirty from before rebuilding the dependencies to after. For normal file rules the two effects are roughly the same. For phony rules, the output is always dirty, so it has changed the order to something counter intuitive. I've fixed that by inserting a fake alwaysRerun at the beginning of every phony, restoring the old behaviour. The fact #519 doesn't get fixed is a separate issue then.

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

No branches or pull requests

3 participants