on master help sign in
Try to fix build artifact caching across "git checkout"

Before this commit, we used timestamps to detect if an interface file (.elmi) needed to be rebuilt. If the .elm file is at t1 and the .elmi file is at t2, no rebuild is needed if (t1 <= t2) This did not work if folks did a `git checkout` which switches to a branch where the .elm file gets older. So I am trying a new thing. Now .elmi files will have a modification time exactly equal to the modification time of the corresponding .elm file. So switching to an older or newer .elm file will always cause a rebuild. This can fail is if two people edit the same file at exactly the same time on different branches. So it is not perfect, but this should happen less often than the corner case we had before. The idea is that we will test it out in the pre-release time. Maybe this trick will not work on certain platforms. We will learn.

commit3521750c19772c2da27c45314b8cbd7d2aeba82b authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 22 May 2018, 14:18 (8 years ago) parent51b10b0
8 files changed+33−30
builder/src/Deps/Verify.hs+3−3 builder/src/Elm/Project.hs+1−1 builder/src/File/Artifacts.hs+6−3 builder/src/File/Compile.hs+3−4 builder/src/File/Plan.hs+1−1 builder/src/Generate/Output.hs+1−1 compiler/src/Compile.hs+7−4 compiler/src/Elm/Compiler.hs+11−13
builder/src/Deps/Verify.hs+3−3
@@ -334,7 +334,7 @@ crush pkg info results =
334334
335335
336336crushHelp :: Set Module.Raw -> Module.Raw -> Compiler.Artifacts -> Maybe Module.Interface
337−crushHelp exposed name (Compiler.Artifacts elmi _ _) =
337+crushHelp exposed name (Compiler.Artifacts _ elmi _ _) =
338338 if Set.member name exposed then
339339 Just elmi
340340
@@ -347,7 +347,7 @@ crushHelp exposed name (Compiler.Artifacts elmi _ _) =
347347
348348
349349addDocs :: Compiler.Artifacts -> [Docs.Module] -> [Docs.Module]
350−addDocs (Compiler.Artifacts _ _ maybeDocs) docsList =
350+addDocs (Compiler.Artifacts _ _ _ maybeDocs) docsList =
351351 case maybeDocs of
352352 Nothing ->
353353 docsList
@@ -361,7 +361,7 @@ addDocs (Compiler.Artifacts _ _ maybeDocs) docsList =
361361
362362
363363addGraph :: Compiler.Artifacts -> Obj.Graph -> Obj.Graph
364−addGraph (Compiler.Artifacts _ elmo _) graph =
364+addGraph (Compiler.Artifacts _ _ elmo _) graph =
365365 Obj.union elmo graph
366366
367367
builder/src/Elm/Project.hs+1−1
@@ -78,7 +78,7 @@ compileForRepl noColors localizer source maybeName =
7878 (dirty, ifaces) <- Plan.plan Nothing summary graph
7979 answers <- Compile.compile project Nothing ifaces dirty
8080 results <- Artifacts.write root answers
81− let (Compiler.Artifacts elmi _ _) = results ! N.replModule
81+ let (Compiler.Artifacts _ elmi _ _) = results ! N.replModule
8282 traverse (Output.generateReplFile noColors localizer summary graph elmi) maybeName
8383
8484
builder/src/File/Artifacts.hs+6−3
@@ -15,6 +15,7 @@ import Data.Map (Map)
1515import qualified Data.Map as Map
1616import qualified Data.Maybe as Maybe
1717import qualified Data.Text.Encoding as Text
18+import qualified System.Directory as Dir
1819
1920import qualified Elm.Compiler as Compiler
2021import qualified Elm.Compiler.Module as Module
@@ -48,11 +49,13 @@ ignore answers =
4849write :: FilePath -> Map Module.Raw Answer -> Task.Task (Map Module.Raw Compiler.Artifacts)
4950write root answers =
5051 let
51− writer name result@(Compiler.Artifacts elmi elmo _) =
52+ writer name result@(Compiler.Artifacts time elmi elmo _) =
5253 do mvar <- newEmptyMVar
5354 void $ forkIO $
54− do Binary.encodeFile (Path.elmi root name) elmi
55+ do let ifacePath = Path.elmi root name
56+ Binary.encodeFile ifacePath elmi
5557 Binary.encodeFile (Path.elmo root name) elmo
58+ Dir.setModificationTime ifacePath time
5659 putMVar mvar result
5760 return mvar
5861 in
@@ -63,7 +66,7 @@ write root answers =
6366writeDocs :: Map Module.Raw Compiler.Artifacts -> FilePath -> Task.Task Docs.Documentation
6467writeDocs results path =
6568 let
66− getDocs (Compiler.Artifacts _ _ docs) =
69+ getDocs (Compiler.Artifacts _ _ _ docs) =
6770 docs
6871 in
6972 case Maybe.mapMaybe getDocs (Map.elems results) of
builder/src/File/Compile.hs+3−4
@@ -84,16 +84,15 @@ compileModule tell project maybeDocsPath answersMVar ifacesMVar name info =
8484 let docs = toDocsFlag name project maybeDocsPath
8585 let imports = makeImports project info
8686 ifaces <- readMVar ifacesMVar
87− let context = Compiler.Context pkg docs imports ifaces
87+ let time = Plan._time info
8888 let source = Plan._src info
89− case Compiler.compile context source of
89+ case Compiler.compile docs pkg imports ifaces time source of
9090 (_warnings, Left errors) ->
9191 do tell (Progress.CompileFileEnd name Progress.Bad)
9292 let path = Plan._path info
93− let time = Plan._time info
9493 putMVar mvar (Bad path time source errors)
9594
96− (_warnings, Right result@(Compiler.Artifacts elmi _ _)) ->
95+ (_warnings, Right result@(Compiler.Artifacts _ elmi _ _)) ->
9796 do tell (Progress.CompileFileEnd name Progress.Good)
9897 let canonicalName = Module.Canonical pkg name
9998 lock <- takeMVar ifacesMVar
builder/src/File/Plan.hs+1−1
@@ -158,7 +158,7 @@ isFresh srcTime cachedFile =
158158 andM
159159 [ Dir.doesFileExist cachedFile
160160 , do cacheTime <- Dir.getModificationTime cachedFile
161− return (cacheTime >= srcTime)
161+ return (cacheTime == srcTime)
162162 ]
163163
164164
builder/src/Generate/Output.hs+1−1
@@ -88,7 +88,7 @@ getInterfaces :: Summary.Summary -> Map.Map Module.Raw Compiler.Artifacts -> I.I
8888getInterfaces (Summary.Summary _ project _ interfaces _) artifacts =
8989 let
9090 pkg = Project.getName project
91− addArtifact home (Compiler.Artifacts elmi _ _) ifaces =
91+ addArtifact home (Compiler.Artifacts _ elmi _ _) ifaces =
9292 Map.insert (ModuleName.Canonical pkg home) elmi ifaces
9393 in
9494 Map.foldrWithKey addArtifact interfaces artifacts
compiler/src/Compile.hs+7−4
@@ -9,6 +9,7 @@ module Compile
99
1010import qualified Data.ByteString as BS
1111import qualified Data.Map as Map
12+import qualified Data.Time.Clock as Time
1213
1314import qualified AST.Canonical as Can
1415import qualified AST.Optimized as Opt
@@ -45,14 +46,15 @@ type ImportDict =
4546
4647data Artifacts =
4748 Artifacts
48− { _elmi :: I.Interface
49+ { _time :: Time.UTCTime
50+ , _elmi :: I.Interface
4951 , _elmo :: Opt.Graph
5052 , _docs :: Maybe Docs.Module
5153 }
5254
5355
54−compile :: DocsFlag -> Pkg.Name -> ImportDict -> I.Interfaces -> BS.ByteString -> Result i Artifacts
55−compile flag pkg importDict interfaces source =
56+compile :: DocsFlag -> Pkg.Name -> ImportDict -> I.Interfaces -> Time.UTCTime -> BS.ByteString -> Result i Artifacts
57+compile flag pkg importDict interfaces time source =
5658 do
5759 valid <- Result.mapError Error.Syntax $
5860 Parse.program pkg source
@@ -76,7 +78,8 @@ compile flag pkg importDict interfaces source =
7678
7779 Result.ok $
7880 Artifacts
79− { _elmi = I.fromModule annotations canonical
81+ { _time = time
82+ , _elmi = I.fromModule annotations canonical
8083 , _elmo = graph
8184 , _docs = documentation
8285 }
compiler/src/Elm/Compiler.hs+11−13
@@ -1,7 +1,6 @@
11{-# LANGUAGE OverloadedStrings #-}
22module Elm.Compiler
33 ( version
4− , Context(..)
54 , Compile.DocsFlag(..)
65 , Compile.Artifacts(..)
76 , compile
@@ -16,6 +15,7 @@ module Elm.Compiler
1615import qualified Data.ByteString as BS
1716import qualified Data.Map as Map
1817import qualified Data.Text as Text
18+import qualified Data.Time.Clock as Time
1919
2020import qualified Compile
2121import qualified Elm.Compiler.Module as M
@@ -44,18 +44,16 @@ version =
4444-- COMPILE
4545
4646
47−data Context =
48− Context
49− { _package :: Pkg.Name
50− , _docsFlag :: Compile.DocsFlag
51− , _imports :: Map.Map M.Raw M.Canonical
52− , _interfaces :: M.Interfaces
53− }
54−
55−
56−compile :: Context -> BS.ByteString -> ([Warning.Warning], Either [Error.Error] Compile.Artifacts)
57−compile (Context pkg docsFlag importDict interfaces) source =
58− Result.run $ Compile.compile docsFlag pkg importDict interfaces source
47+compile
48+ :: Compile.DocsFlag
49+ -> Pkg.Name
50+ -> Map.Map M.Raw M.Canonical
51+ -> M.Interfaces
52+ -> Time.UTCTime
53+ -> BS.ByteString
54+ -> ( [Warning.Warning], Either [Error.Error] Compile.Artifacts )
55+compile docsFlag pkg importDict interfaces time source =
56+ Result.run $ Compile.compile docsFlag pkg importDict interfaces time source
5957
6058
6159