diff --git a/addSanity.sh b/addSanity.sh index 7c66130a..5a0c3806 100755 --- a/addSanity.sh +++ b/addSanity.sh @@ -15,8 +15,8 @@ function replace_in_file() { export -f replace_in_file -find builder -type f -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map ((!))/import Sanity ((!), debugFind) -- Data.Map ((!))/g" "$@"' _ {} -find compiler -type f -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map ((!))/import Sanity ((!), debugFind) -- Data.Map ((!))/g" "$@"' _ {} +find builder -type f -name "*.hs" -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map ((!))/import Sanity ((!), debugFind) -- Data.Map ((!))/g" "$@"' _ {} +find compiler -type f -name "*.hs" -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map ((!))/import Sanity ((!), debugFind) -- Data.Map ((!))/g" "$@"' _ {} -find builder -type f -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map.Strict ((!))/import Sanity ((!), debugFind) -- Data.Map.Strict ((!))/g" "$@"' _ {} -find compiler -type f -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map.Strict ((!))/import Sanity ((!), debugFind) -- Data.Map.Strict ((!))/g" "$@"' _ {} +find builder -type f -name "*.hs" -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map.Strict ((!))/import Sanity ((!), debugFind) -- Data.Map.Strict ((!))/g" "$@"' _ {} +find compiler -type f -name "*.hs" -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Data.Map.Strict ((!))/import Sanity ((!), debugFind) -- Data.Map.Strict ((!))/g" "$@"' _ {} diff --git a/compiler/src/Compile.hs b/compiler/src/Compile.hs index f05ffef0..c3af2fa7 100644 --- a/compiler/src/Compile.hs +++ b/compiler/src/Compile.hs @@ -58,6 +58,9 @@ data Artifacts = compile :: Pkg.Name -> Map.Map ModuleName.Raw I.Interface -> Src.Module -> Either E.Error Artifacts compile pkg ifaces modul = do + -- Allow global opt-out of Lamdera compile modifications + Lamdera.alternativeImplementationWhen (not Lamdera.isWireEnabled_) (compile_ pkg ifaces modul) $ do + -- @TEMPORARY debugging -- Inject stub definitions for wire functions, so the canonicalize phase can run -- Necessary for user-code which references yet-to-be generated functions diff --git a/extra/Lamdera.hs b/extra/Lamdera.hs index eea17c0a..e87970bd 100644 --- a/extra/Lamdera.hs +++ b/extra/Lamdera.hs @@ -40,6 +40,9 @@ module Lamdera -- , isTypeSnapshot , isLamdera , isLamdera_ + , disableWire + , isWireEnabled + , isWireEnabled_ , isTest , isLiveMode , setLiveMode @@ -409,6 +412,25 @@ isLamdera_ :: Bool isLamdera_ = unsafePerformIO $ isLamdera +{-# NOINLINE useWire_ #-} +useWire_ :: MVar Bool +useWire_ = unsafePerformIO $ newMVar True + +disableWire :: IO () +disableWire = do + debug $ "⚡️ disableWire" + modifyMVar_ useWire_ (\_ -> pure False) + +{-# NOINLINE isWireEnabled #-} +isWireEnabled :: IO Bool +isWireEnabled = do + readMVar useWire_ + +{-# NOINLINE isWireEnabled_ #-} +isWireEnabled_ :: Bool +isWireEnabled_ = unsafePerformIO $ isWireEnabled + + isTest :: IO Bool isTest = do diff --git a/extra/Lamdera/Compile.hs b/extra/Lamdera/Compile.hs index b9fe514d..8a0e621f 100644 --- a/extra/Lamdera/Compile.hs +++ b/extra/Lamdera/Compile.hs @@ -92,6 +92,7 @@ makeDev root paths = do , _output = Just Make.DevNull , _report = Nothing , _docs = Nothing + , _noWire = False } wait r -- The compilation process ends by printing to terminal in a way that overwrites diff --git a/extra/Lamdera/Evergreen/MigrationGenerator.hs b/extra/Lamdera/Evergreen/MigrationGenerator.hs index e1228e54..295f6876 100644 --- a/extra/Lamdera/Evergreen/MigrationGenerator.hs +++ b/extra/Lamdera/Evergreen/MigrationGenerator.hs @@ -7,6 +7,7 @@ module Lamdera.Evergreen.MigrationGenerator where import Data.Map (Map) import qualified Data.Map as Map +import qualified Sanity import qualified Data.Set as Set import qualified Data.List as List import qualified Data.Text as T @@ -45,7 +46,7 @@ betweenVersions coreTypeDiffs oldVersion newVersion root = do case Map.lookup (N.fromChars moduleNameString) interfaces of Just interface -> do debug $ "starting generatefor" - generateFor coreTypeDiffs oldVersion newVersion interfaces (interfaces Map.! (N.fromChars $ "Evergreen.V" <> show newVersion <> ".Types")) + generateFor coreTypeDiffs oldVersion newVersion interfaces (interfaces Sanity.! (N.fromChars $ "Evergreen.V" <> show newVersion <> ".Types")) Nothing -> error $ "Fatal: could not find the module `" <> moduleNameString <> "`, please report this issue in Discord with your project code." diff --git a/removeSanity.sh b/removeSanity.sh index c4101227..b7089588 100755 --- a/removeSanity.sh +++ b/removeSanity.sh @@ -20,5 +20,5 @@ function replace_in_file() { export -f replace_in_file -find builder -type f -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Sanity ((!), debugFind) --/import/g" "$@"' _ {} -find compiler -type f -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Sanity ((!), debugFind) --/import/g" "$@"' _ {} +find builder -type f -name "*.hs" -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Sanity ((!), debugFind) --/import/g" "$@"' _ {} +find compiler -type f -name "*.hs" -print0 | xargs -0 -I {} bash -c 'replace_in_file "s/import Sanity ((!), debugFind) --/import/g" "$@"' _ {} diff --git a/terminal/src/Main.hs b/terminal/src/Main.hs index 660b102a..bb5ebbf6 100644 --- a/terminal/src/Main.hs +++ b/terminal/src/Main.hs @@ -209,6 +209,7 @@ make = |-- flag "output" Make.output "Specify the name of the resulting JS file. For example --output=assets/elm.js to generate the JS at assets/elm.js or --output=/dev/null to generate no output at all!" |-- flag "report" Make.reportType "You can say --report=json to get error messages as JSON. This is only really useful if you are an editor plugin. Humans should avoid it!" |-- flag "docs" Make.docsFile "Generate a JSON file of documentation for a package. Eventually it will be possible to preview docs with `reactor` because it is quite hard to deal with these JSON files directly." + |-- onOff "no-wire" "Explicitly disable Lamdera's wire codegen." in Terminal.Command "make" Uncommon details example (zeroOrMore elmFile) makeFlags Make.run diff --git a/terminal/src/Make.hs b/terminal/src/Make.hs index 1e9a4766..947ffc42 100644 --- a/terminal/src/Make.hs +++ b/terminal/src/Make.hs @@ -33,6 +33,7 @@ import qualified Stuff import Terminal (Parser(..)) +import qualified Lamdera import qualified Lamdera.PostCompile -- FLAGS @@ -45,6 +46,7 @@ data Flags = , _output :: Maybe Output , _report :: Maybe ReportType , _docs :: Maybe FilePath + , _noWire :: Bool -- @LAMDERA } @@ -66,9 +68,10 @@ type Task a = Task.Task Exit.Make a run :: [FilePath] -> Flags -> IO () -run paths flags@(Flags _ _ _ report _) = +run paths flags@(Flags _ _ _ report _ noWire) = do style <- getStyle report maybeRoot <- Stuff.findRoot + Lamdera.onlyWhen noWire Lamdera.disableWire Reporting.attemptWithStyle style Exit.makeToReport $ case maybeRoot of Just root -> runHelp root paths style flags @@ -76,7 +79,7 @@ run paths flags@(Flags _ _ _ report _) = runHelp :: FilePath -> [FilePath] -> Reporting.Style -> Flags -> IO (Either Exit.Make ()) -runHelp root paths style (Flags debug optimize maybeOutput _ maybeDocs) = +runHelp root paths style (Flags debug optimize maybeOutput _ maybeDocs _) = BW.withScope $ \scope -> Stuff.withRootLock root $ Task.run $ do desiredMode <- getMode debug optimize @@ -329,7 +332,7 @@ isDevNull name = -- Clone of run that uses attemptWithStyle_cleanup run_cleanup :: IO () -> [FilePath] -> Flags -> IO () -run_cleanup cleanup paths flags@(Flags _ _ _ report _) = +run_cleanup cleanup paths flags@(Flags _ _ _ report _ _) = do style <- getStyle report maybeRoot <- Stuff.findRoot Reporting.attemptWithStyle_cleanup cleanup style Exit.makeToReport $