From f134fd2756e2a1aa7d353537f0b1759edf0d1d9c Mon Sep 17 00:00:00 2001 From: Decio Ferreira Date: Fri, 13 Dec 2024 23:03:36 +0000 Subject: [PATCH] WIP clear debugging --- bin/index.js | 2 +- lib/guida.sh | 10 +++---- src/Builder/Deps/Solver.elm | 4 --- src/Builder/File.elm | 6 ++-- src/System/IO.elm | 55 +++++++++++++++++-------------------- src/Utils/Crash.elm | 2 +- src/Utils/Main.elm | 26 +++++------------- 7 files changed, 42 insertions(+), 63 deletions(-) diff --git a/bin/index.js b/bin/index.js index 7d9c8a1ff..50df07f1b 100755 --- a/bin/index.js +++ b/bin/index.js @@ -12,7 +12,7 @@ const crypto = require("node:crypto"); const AdmZip = require("adm-zip"); const which = require("which"); const tmp = require("tmp"); -const { Elm } = require("./guida.js"); +const { Elm } = require("./guida.min.js"); const FormData = require("form-data"); const rl = readline.createInterface({ diff --git a/lib/guida.sh b/lib/guida.sh index 22e493ffb..1443cae3a 100755 --- a/lib/guida.sh +++ b/lib/guida.sh @@ -7,10 +7,10 @@ set -e js="bin/guida.js" min="bin/guida.min.js" -guida make --output=$js $@ +elm make --optimize --output=$js $@ -# uglifyjs $js --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | uglifyjs --mangle --output $min +uglifyjs $js --compress "pure_funcs=[F2,F3,F4,F5,F6,F7,F8,F9,A2,A3,A4,A5,A6,A7,A8,A9],pure_getters,keep_fargs=false,unsafe_comps,unsafe" | uglifyjs --mangle --output $min -# echo "Initial size: $(cat $js | wc -c) bytes ($js)" -# echo "Minified size:$(cat $min | wc -c) bytes ($min)" -# echo "Gzipped size: $(cat $min | gzip -c | wc -c) bytes" \ No newline at end of file +echo "Initial size: $(cat $js | wc -c) bytes ($js)" +echo "Minified size:$(cat $min | wc -c) bytes ($min)" +echo "Gzipped size: $(cat $min | gzip -c | wc -c) bytes" \ No newline at end of file diff --git a/src/Builder/Deps/Solver.elm b/src/Builder/Deps/Solver.elm index 6bb18e807..99f2a761c 100644 --- a/src/Builder/Deps/Solver.elm +++ b/src/Builder/Deps/Solver.elm @@ -447,10 +447,6 @@ initEnv = Utils.newEmptyMVar |> IO.bind (\mvar -> - let - _ = - Debug.log "mvar1" mvar - in Utils.forkIO (IO.bind (Utils.putMVar Http.managerEncoder mvar) Http.getManager) |> IO.bind (\_ -> diff --git a/src/Builder/File.elm b/src/Builder/File.elm index b6be841fc..4a4ec774c 100644 --- a/src/Builder/File.elm +++ b/src/Builder/File.elm @@ -57,7 +57,7 @@ writeBinary encoder path value = readBinary : Decode.Decoder a -> FilePath -> IO (Maybe a) readBinary decoder path = - Utils.dirDoesFileExist (Debug.log "path1" path) + Utils.dirDoesFileExist path |> IO.bind (\pathExists -> if pathExists then @@ -164,7 +164,7 @@ writeEntry destination root entry = exists : FilePath -> IO Bool exists path = - Utils.dirDoesFileExist (Debug.log "path2" path) + Utils.dirDoesFileExist path @@ -173,7 +173,7 @@ exists path = remove : FilePath -> IO () remove path = - Utils.dirDoesFileExist (Debug.log "path3" path) + Utils.dirDoesFileExist path |> IO.bind (\exists_ -> if exists_ then diff --git a/src/System/IO.elm b/src/System/IO.elm index 912f38125..7726c76b3 100644 --- a/src/System/IO.elm +++ b/src/System/IO.elm @@ -226,10 +226,6 @@ type Msg update : Msg -> Model -> ( Model, Cmd Msg ) update msg model = - let - _ = - Debug.log "next" model.next - in case msg of PureMsg index (IO fn) -> case fn index model of @@ -317,10 +313,6 @@ update msg model = ( { newRealWorld | next = Dict.insert index (ReplGetInputLineNext next) model.next }, sendReplGetInputLine { index = index, prompt = prompt } ) ( newRealWorld, DirDoesFileExist next filename ) -> - let - _ = - Debug.log "DirDoesFileExist" ( index, filename ) - in ( { newRealWorld | next = Dict.insert index (DirDoesFileExistNext next) model.next }, sendDirDoesFileExist { index = index, filename = filename } ) ( newRealWorld, DirCreateDirectoryIfMissing next createParents filename ) -> @@ -359,39 +351,38 @@ update msg model = ( newRealWorld, ReplGetInputLineWithInitial next prompt left right ) -> ( { newRealWorld | next = Dict.insert index (ReplGetInputLineWithInitialNext next) model.next }, sendReplGetInputLineWithInitial { index = index, prompt = prompt, left = left, right = right } ) - ( newRealWorld, ReadMVar next ) -> + ( newRealWorld, ReadMVarWaiting next ) -> ( { newRealWorld | next = Dict.insert index (ReadMVarNext next) model.next }, Cmd.none ) + ( newRealWorld, ReadMVarDone next value ) -> + update (ReadMVarMsg index value) { newRealWorld | next = Dict.insert index (ReadMVarNext next) model.next } + ( newRealWorld, TakeMVarWaiting next ) -> ( { newRealWorld | next = Dict.insert index (TakeMVarNext next) model.next }, Cmd.none ) - ( newRealWorld, TakeMVarTaken next value maybePutIndex ) -> + ( newRealWorld, TakeMVarDone next value maybePutIndex ) -> let ( updatedModel, updatedCmd ) = update (ReadMVarMsg index value) { newRealWorld | next = Dict.insert index (TakeMVarNext next) model.next } in - case Debug.log "maybePutIndex" maybePutIndex of + case maybePutIndex of Just putIndex -> - update (PutMVarMsg (Debug.log "putIndex" putIndex)) updatedModel + update (PutMVarMsg putIndex) updatedModel |> Tuple.mapSecond (\cmd -> Cmd.batch [ cmd, updatedCmd ]) Nothing -> ( updatedModel, updatedCmd ) ( newRealWorld, PutMVarWaiting next ) -> - ( { newRealWorld | next = Dict.insert (Debug.log "INDEX1" index) (PutMVarNext next) model.next }, Cmd.none ) + ( { newRealWorld | next = Dict.insert index (PutMVarNext next) model.next }, Cmd.none ) ( newRealWorld, PutMVarDone next readSubscriberIds maybeTakeIndex value ) -> - let - _ = - Debug.log "readSubscriberIds maybeTakeIndex" ( readSubscriberIds, maybeTakeIndex ) - in List.foldr (\readSubscriberId ( accModel, accCmd ) -> - update (ReadMVarMsg (Debug.log "readSubscriberId" readSubscriberId) value) accModel + update (ReadMVarMsg readSubscriberId value) accModel |> Tuple.mapSecond (\cmd -> Cmd.batch [ cmd, accCmd ]) ) - (update (PutMVarMsg index) { newRealWorld | next = Dict.insert (Debug.log "INDEX2" index) (PutMVarNext next) model.next }) + (update (PutMVarMsg index) { newRealWorld | next = Dict.insert index (PutMVarNext next) model.next }) readSubscriberIds GetLineMsg index input -> @@ -527,8 +518,8 @@ update msg model = Just (DirDoesFileExistNext fn) -> update (PureMsg index (fn value)) model - nextFn -> - crash ("DirDoesFileExistMsg " ++ String.fromInt index ++ " - " ++ Debug.toString nextFn) + _ -> + crash "DirDoesFileExistMsg" DirCreateDirectoryIfMissingMsg index -> case Dict.get index model.next of @@ -836,24 +827,25 @@ type ION a | ExitWith (a -> IO a) Int | DirFindExecutable (Maybe FilePath -> IO a) FilePath | ReplGetInputLine (Maybe String -> IO a) String - | PutMVarWaiting (() -> IO a) - | PutMVarDone (() -> IO a) (List Int) (Maybe Int) Encode.Value | DirDoesFileExist (Bool -> IO a) FilePath | DirCreateDirectoryIfMissing (() -> IO a) Bool FilePath | LockFile (() -> IO a) FilePath | UnlockFile (() -> IO a) FilePath | DirGetModificationTime (Int -> IO a) FilePath - | TakeMVarWaiting (Encode.Value -> IO a) - | TakeMVarTaken (Encode.Value -> IO a) Encode.Value (Maybe Int) | DirDoesDirectoryExist (Bool -> IO a) FilePath | DirCanonicalizePath (String -> IO a) FilePath - | ReadMVar (Encode.Value -> IO a) | BinaryDecodeFileOrFail (Encode.Value -> IO a) FilePath | Write (() -> IO a) FilePath Encode.Value | DirRemoveFile (() -> IO a) FilePath | DirRemoveDirectoryRecursive (() -> IO a) FilePath | DirWithCurrentDirectory (() -> IO a) FilePath | ReplGetInputLineWithInitial (Maybe String -> IO a) String String String + | ReadMVarWaiting (Encode.Value -> IO a) + | ReadMVarDone (Encode.Value -> IO a) Encode.Value + | TakeMVarWaiting (Encode.Value -> IO a) + | TakeMVarDone (Encode.Value -> IO a) Encode.Value (Maybe Int) + | PutMVarWaiting (() -> IO a) + | PutMVarDone (() -> IO a) (List Int) (Maybe Int) Encode.Value type alias RealWorld = @@ -993,14 +985,17 @@ bind f (IO ma) = ( s1, ReplGetInputLineWithInitial next prompt left right ) -> ( s1, ReplGetInputLineWithInitial (\value -> bind f (next value)) prompt left right ) - ( s1, ReadMVar next ) -> - ( s1, ReadMVar (\value -> bind f (next value)) ) + ( s1, ReadMVarWaiting next ) -> + ( s1, ReadMVarWaiting (\value -> bind f (next value)) ) + + ( s1, ReadMVarDone next readValue ) -> + ( s1, ReadMVarDone (\value -> bind f (next value)) readValue ) ( s1, TakeMVarWaiting next ) -> ( s1, TakeMVarWaiting (\value -> bind f (next value)) ) - ( s1, TakeMVarTaken next takenValue maybePutIndex ) -> - ( s1, TakeMVarTaken (\value -> bind f (next value)) takenValue maybePutIndex ) + ( s1, TakeMVarDone next takenValue maybePutIndex ) -> + ( s1, TakeMVarDone (\value -> bind f (next value)) takenValue maybePutIndex ) ( s1, PutMVarWaiting next ) -> ( s1, PutMVarWaiting (\() -> bind f (next ())) ) diff --git a/src/Utils/Crash.elm b/src/Utils/Crash.elm index 8ec65155b..76f69679b 100644 --- a/src/Utils/Crash.elm +++ b/src/Utils/Crash.elm @@ -3,4 +3,4 @@ module Utils.Crash exposing (crash) crash : String -> a crash str = - Debug.todo str + crash str diff --git a/src/Utils/Main.elm b/src/Utils/Main.elm index 6733697ad..be2f00bde 100644 --- a/src/Utils/Main.elm +++ b/src/Utils/Main.elm @@ -140,7 +140,7 @@ import Json.Encode as Encode import Maybe.Extra as Maybe import Prelude import System.Exit as Exit -import System.IO as IO exposing (IO(..), MVarSubscriber(..)) +import System.IO as IO exposing (IO(..)) import Time import Utils.Crash exposing (crash) @@ -935,10 +935,6 @@ newMVar encoder value = newEmptyMVar |> IO.bind (\mvar -> - let - _ = - Debug.log "mvar2" mvar - in putMVar encoder mvar value |> IO.fmap (\_ -> mvar) ) @@ -952,11 +948,11 @@ readMVar decoder (MVar ref) = Just mVar -> case mVar.value of Just value -> - ( s, IO.Pure value ) + ( s, IO.ReadMVarDone IO.pure value ) Nothing -> ( { s | mVars = Array.set ref { mVar | subscribers = IO.ReadSubscriber index :: mVar.subscribers } s.mVars } - , IO.ReadMVar IO.pure + , IO.ReadMVarWaiting IO.pure ) Nothing -> @@ -1002,7 +998,7 @@ takeMVar decoder (MVar ref) = ( Nothing, subscribers, Nothing ) in ( { s | mVars = Array.set ref { mVar | subscribers = newSubscribers, value = newValue } s.mVars } - , IO.TakeMVarTaken IO.pure value maybePutIndex + , IO.TakeMVarDone IO.pure value maybePutIndex ) Nothing -> @@ -1033,7 +1029,7 @@ putMVar encoder (MVar ref) value = case mVar.value of Just _ -> ( { s | mVars = Array.set ref { mVar | subscribers = IO.PutSubscriber index (encoder value) :: mVar.subscribers } s.mVars } - , Debug.log "PutMVarWaiting" (IO.PutMVarWaiting IO.pure) + , IO.PutMVarWaiting IO.pure ) Nothing -> @@ -1070,15 +1066,11 @@ putMVar encoder (MVar ref) value = (IO.TakeSubscriber takeIndex) :: remainingSubscribers -> ( Nothing, Just takeIndex, remainingSubscribers ) - all -> - let - _ = - Debug.log "ALL!!!" all - in + _ -> ( Just encodedValue, Nothing, nonReadSubscribers ) in ( { s | mVars = Array.set ref { mVar | subscribers = subscribers, value = newValue } s.mVars } - , Debug.log "PutMVarDone" (IO.PutMVarDone IO.pure readSubscriberIds maybeTakeIndex encodedValue) + , IO.PutMVarDone IO.pure readSubscriberIds maybeTakeIndex encodedValue ) _ -> @@ -1090,10 +1082,6 @@ newEmptyMVar : IO (MVar a) newEmptyMVar = IO (\_ s -> - let - _ = - Debug.log "newEmptyMVar" (Array.length s.mVars) - in ( { s | mVars = Array.push { subscribers = [], value = Nothing } s.mVars } , IO.Pure (MVar (Array.length s.mVars)) )