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 27, 2023
1 parent 9314a0f commit 8f59f07
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 75 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
3 changes: 3 additions & 0 deletions extra/Lamdera/CLI/Check.hs
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ buildProductionJsFiles root inProduction_ versionInfo = do
, _output = Just (Make.JS "backend-app.js")
, _report = Nothing
, _docs = Nothing
, _noWire = False
}

Make.run ["src" </> "LFR.elm"] $
Expand All @@ -594,6 +595,7 @@ buildProductionJsFiles root inProduction_ versionInfo = do
, _output = Just (Make.JS "frontend-app.js")
, _report = Nothing
, _docs = Nothing
, _noWire = False
}

Lamdera.AppConfig.writeUsage
Expand Down Expand Up @@ -693,6 +695,7 @@ migrationCheck root nextVersion = do
, _output = Just (Make.DevNull)
, _report = Nothing
, _docs = Nothing
, _noWire = False
}

-- @TODO this is because the migrationCheck does weird terminal stuff that mangles the display... how to fix this?
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
93 changes: 28 additions & 65 deletions test/Test.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,31 @@ For more information on how to use the GHCi debugger, see the GHC User's Guide.
-}



-- Current target for ghci :rr command. See ~/.ghci config file, which should contain
-- something like `:def rr const $ return $ unlines [":r","Test.target"]`

-- target = Test.all
-- target = checkProject
--target =
-- Test.Check.checkWithParams "/Users/mario/dev/projects/lamdera-dashboard"
-- Test.Check.checkWithParams "/Users/mario/lamdera/test/sheep-game" "sheep-game"

-- target = buildTestHarnessToProductionJs
-- target = checkProjectCompiles
-- target = previewProject
-- target = liveReloadLive
target = Test.all
-- target = checkUserConfig
-- target = Test.Wire.buildAllPackages
-- target = Lamdera.CLI.Login.run () ()
-- target = Dir.withCurrentDirectory "/Users/mario/dev/projects/lamdera-test" $ Lamdera.CLI.Reset.run () ()
-- target = Lamdera.Diff.run
-- target = Lamdera.ReverseProxy.start
-- target = Test.Check.mockBuildSh "/Users/mario/lamdera-deploys/test-local-v1" "test-local"
-- target = Test.Check.mockBuildSh "/Users/mario/dev/test/lamdera-init" "test-local"
-- target = Test.Caching.all

-- target = EasyTest.run Test.WebGL.suite


checkProject = do
Expand All @@ -123,38 +141,6 @@ previewProject = do
Dir.withCurrentDirectory p $ Lamdera.CLI.Deploy.run () ()


--target =
-- Test.Check.checkWithParams "/Users/mario/dev/projects/lamdera-dashboard"
-- Test.Check.checkWithParams "/Users/mario/lamdera/test/sheep-game" "sheep-game"

-- target = buildTestHarnessToProductionJs
-- target = checkProjectCompiles
-- target = previewProject
-- target = liveReloadLive
-- target = Test.Wire.all
-- target = checkUserConfig
-- target = Test.Wire.buildAllPackages
-- target = Lamdera.CLI.Login.run () ()
-- target = Dir.withCurrentDirectory "/Users/mario/dev/projects/lamdera-test" $ Lamdera.CLI.Reset.run () ()
-- target = Lamdera.Diff.run
-- target = Lamdera.ReverseProxy.start
-- target = Test.Check.mockBuildSh "/Users/mario/lamdera-deploys/test-local-v1" "test-local"
-- target = Test.Check.mockBuildSh "/Users/mario/dev/test/lamdera-init" "test-local"
-- target = Test.Caching.all

-- target = do
-- let p = "/Users/mario/dev/projects/elm-pages/examples/end-to-end"
-- Dir.setCurrentDirectory p
-- Dir.setCurrentDirectory p
-- withCurrentDirectory p $
-- Make.run ["app/Route/Index.elm"]
-- $ Make.Flags
-- { _debug = False
-- , _optimize = False
-- , _output = Nothing
-- , _report = Nothing
-- , _docs = Nothing
-- }

checkProjectCompiles = do
setEnv "LDEBUG" "1"
Expand All @@ -164,28 +150,21 @@ checkProjectCompiles = do

-- Lamdera.CLI.Check.checkUserProjectCompiles runs in async so we don't get the trace
-- root = "/Users/mario/dev/test/style-elements"
root = "/Users/mario/dev/test/lamdera-init"
scaffold = "src/Frontend.elm"
-- root = "/Users/mario/dev/test/lamdera-init"
-- root = "/Users/mario/dev/test/cdvienne-lamdera-fail/xbus-gui"
-- scaffold = "src/Main.elm"
root = "/Users/mario/dev/test/cdvienne-lamdera-fail/xbus-gui/elm-protoc-types"
scaffold = "src/Proto/Google/Protobuf.elm"

-- let root = "/Users/mario/dev/test/realia/staging"
-- scaffold = "src/LFR.elm"
-- let root = "/Users/mario/dev/projects/elmcraft"
-- scaffold = "elm-stuff/elm-pages/.elm-pages/Main.elm"
tmp = lamderaCache root <> "/tmp.js"

Ext.Common.setProjectRoot root
Lamdera.Compile.makeDev root [scaffold]

-- Dir.withCurrentDirectory root $
-- Make.run_cleanup (pure ()) [scaffold] $
-- Make.Flags
-- { _debug = False
-- , _optimize = True
-- -- We don't use Make.DevNull as it does not actually compile to JS,
-- -- thus we never get warnings about Debug.* usage which we want.
-- , _output = Just (Make.JS tmp)
-- , _report = Nothing
-- , _docs = Nothing
-- }


-- target = do
-- setEnv "LOVR" "/Users/mario/dev/projects/lamdera/overrides"
Expand Down Expand Up @@ -225,24 +204,10 @@ liveReloadLive = do
setEnv "LDEBUG" "1"
setEnv "EXPERIMENTAL" "1"

-- let p = "/Users/mario/lamdera/test/v1"
-- let p = "/Users/mario/dev/projects/bento-life"
let p = "/Users/mario/dev/projects/lamdera-dashboard"

let p = "/Users/mario/lamdera/test/v1"
-- let p = "/Users/mario/dev/test/lamdera-init"
-- let p = "/Users/mario/dev/test/nu-ashworld-lamdera"
-- let p = "/Users/mario/dev/test/town-collab"

-- let p = "/Users/mario/dev/projects/otstats"
-- let p = "/Users/mario/work/codespecs"
-- let p = "/Users/mario/lamdera/overrides/packages/elm/bytes/1.0.8/benchmarks"

-- Wire debugging feature in LocalDev WIP
-- let p = "/Users/mario/dev/test/wire-failure/230623-best-web-vitals/best-web-vitals-v10"
-- let p = "/Users/mario/dev/test/wire-failure/230623-best-web-vitals/best-web-vitals-v9"
-- let p = "/Users/mario/dev/test/wire-failure/230623-best-web-vitals/newv1snaps"
-- let p = "/Users/mario/dev/test/best-web-vitals"

-- rmdir "/Users/mario/.elm"
-- rmdir $ p <> "/elm-stuff"

Expand Down Expand Up @@ -278,8 +243,6 @@ liveReloadLive = do
-- "src/Bytes/Encode.elm"
-- "withDebug"

target = EasyTest.run Test.WebGL.suite

all =
EasyTest.run allTests

Expand Down

0 comments on commit 8f59f07

Please sign in to comment.