GHC's caching does not notice link target changes
Summary
If I've previously compiled a file that's a hard or symbolic link to a file A.hs, and then change that link to point to B.hs, GHC reuses the cached build, even though it shouldn't.
Steps to reproduce
Here's a script that exemplifies the problem:
echo 'main = putStrLn "Hello from A"' > A.hs
echo 'main = putStrLn "Hello from B"' > B.hs
ln -f A.hs Main.hs
echo "Main.hs is now:"
cat Main.hs
echo ""
echo "Compiling and running Main.hs:"
ghc Main.hs && ./Main
echo ""
ln -f B.hs Main.hs
echo "Main.hs is now:"
cat Main.hs
echo ""
echo "Compiling and running Main.hs:"
ghc Main.hs && ./Main
echo ""
echo "Touching Main.hs"
echo ""
touch Main.hs
echo "Compiling and running Main.hs:"
ghc Main.hs && ./Main
Running this script prints:
Main.hs is now:
main = putStrLn "Hello from A"
Compiling and running Main.hs:
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
Hello from A
Main.hs is now:
main = putStrLn "Hello from B"
Compiling and running Main.hs:
Hello from A
Touching Main.hs
Compiling and running Main.hs:
[1 of 1] Compiling Main ( Main.hs, Main.o )
Linking Main ...
Hello from B
Observe that the second compilation's result doesn't match the content of the input file. It does however work if the file is touched first.
Edit: I get the same result if I pass -s
to ln
in the script above to use symbolic links instead of hard links.
Expected behavior
The second compilation should result in a program that prints "Hello from B".
Environment
- GHC version used: 8.6.5
Optional:
- Operating System: Happens on both Manjaro Linux with kernel 5.3.7 and Ubuntu 18.04.2 LTS
- System Architecture: x86_64