Compiler: `elm make` does not recompile all modules that need to be recompiled

Created on 20 Jul 2019  路  3Comments  路  Source: elm/compiler

Quick Summary: elm make often does not correctly determine which files need to be recompiled when a module is changed that is used by multiple entrypoints.

SSCCE

  • Create an elm.json with elm init

  • create src/M1.elm:

module M1 exposing (A1)


type alias A1 =
    Int
  • create src/M3.elm:
module M3 exposing (A2)

import M1


type alias A2 =
    M1.A1
  • create src/Main1.elm:
module Main1 exposing (x)

import M3


x : M3.A2
x =
    0
  • create src/Main2.elm:
module Main2 exposing (unused)

import M1


unused =
    ()
  • remove elm-stuff if it already exists with rm -Rf ./elm-stuff
  • compile Main1 with elm make src/Main1.elm --output /dev/null
  • make the following changes to the files (change Int to String in M1, and 0 to "" in Main1):
--- a/src/M1.elm
+++ b/src/M1.elm
@@ -5 +5 @@ type alias A1 =
-    Int
+    String
--- a/src/Main1.elm
+++ b/src/Main1.elm
@@ -8 +8 @@ x =
-    0
+    ""
  • compile Main2 with elm make src/Main2.elm --output /dev/null
  • try to compile Main1 with elm make src/Main1.elm --output /dev/null

This results in the following incorrect error:

$ elm make src/Main1.elm --output /dev/null
Detected problems in 1 module.
-- TYPE MISMATCH ------------------------------------------------- src/Main1.elm

Something is off with the body of the `x` definition:

8|     ""
       ^^
The body is a string of type:

    String

But the type annotation on `x` says it should be:

    M3.A2

Note that deleting elm-stuff causes both files to then compile successfully.


  • Elm: 0.19.1-alpha-3, 0.19.1-alpha-2, 0.19.1-alpha-1, 0.19.0
  • Browser: N/A
  • Operating System: MacOS 10.13.6

Additional info

If you don't change Main1 when changing M1, then following the rest of the steps will result in Main1 incorrectly compiling successfully (deleting elm-stuff will make it give the correct compilation error).

bug

Most helpful comment

Confirmed that the originally observed reproducible issue on our large codebase is fixed with alpha-4 馃帀

All 3 comments

Thank you for the excellent SSCCE. This made it really easy to understand the problem and test fixes!

The fix is spread across three commits:

The danger here is that there is some logic mistake that leads to compiling modules more than is necessary, so it will be important to have people look at the Success! Compiled 1 module. message to make sure that "modifying a file without changing the public API" always triggers just one recompile. It should never cascade, even across different builds with different entrypoints!

Anyway, thanks again for the great SSCCE!

This appears to be fixed for the SSCCE in alpha-4. I'll try to confirm it against the original large test case...

Confirmed that the originally observed reproducible issue on our large codebase is fixed with alpha-4 馃帀

Was this page helpful?
0 / 5 - 0 ratings

Related issues

willnwhite picture willnwhite  路  4Comments

ccapndave picture ccapndave  路  3Comments

maxsnew picture maxsnew  路  4Comments

torepettersen picture torepettersen  路  4Comments

zoren picture zoren  路  5Comments