Skip to content

Commit

Permalink
Add --no-wire for wire opt-out debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
supermario committed Oct 24, 2023
1 parent 9314a0f commit 91e209a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 10 deletions.
8 changes: 4 additions & 4 deletions addSanity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" "$@"' _ {}
3 changes: 3 additions & 0 deletions compiler/src/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 22 additions & 0 deletions extra/Lamdera.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ module Lamdera
-- , isTypeSnapshot
, isLamdera
, isLamdera_
, disableWire
, isWireEnabled
, isWireEnabled_
, isTest
, isLiveMode
, setLiveMode
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions extra/Lamdera/Compile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion extra/Lamdera/Evergreen/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."
Expand Down
4 changes: 2 additions & 2 deletions removeSanity.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" "$@"' _ {}
1 change: 1 addition & 0 deletions terminal/src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 6 additions & 3 deletions terminal/src/Make.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import qualified Stuff
import Terminal (Parser(..))


import qualified Lamdera
import qualified Lamdera.PostCompile

-- FLAGS
Expand All @@ -45,6 +46,7 @@ data Flags =
, _output :: Maybe Output
, _report :: Maybe ReportType
, _docs :: Maybe FilePath
, _noWire :: Bool -- @LAMDERA
}


Expand All @@ -66,17 +68,18 @@ 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
Nothing -> return $ Left $ Exit.MakeNoOutline


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
Expand Down Expand Up @@ -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 $
Expand Down

0 comments on commit 91e209a

Please sign in to comment.