From 011718fb8ecd653503d5192f6e96a08e4bd5b813 Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Wed, 29 Nov 2023 15:09:06 -0500 Subject: [PATCH 1/2] in update, don't bother typechecking again if we haven't changed the unison file --- .../Codebase/Editor/HandleInput/Update2.hs | 40 +++++++++++++------ .../transcripts/addupdatemessages.output.md | 4 -- .../fix-1381-excess-propagate.output.md | 4 -- unison-src/transcripts/fix1356.output.md | 4 -- unison-src/transcripts/merges.output.md | 4 -- .../transcripts/move-namespace.output.md | 12 ------ unison-src/transcripts/reset.output.md | 4 -- .../update-ignores-lib-namespace.output.md | 4 -- .../transcripts/update-on-conflict.output.md | 4 -- ...e-term-aliases-in-different-ways.output.md | 4 -- .../update-term-to-different-type.output.md | 4 -- .../update-term-with-alias.output.md | 4 -- unison-src/transcripts/update-term.output.md | 4 -- .../update-test-to-non-test.output.md | 4 -- .../update-type-add-constructor.output.md | 4 -- .../update-type-add-field.output.md | 4 -- .../update-type-add-new-record.output.md | 4 -- .../update-type-add-record-field.output.md | 4 -- .../update-type-constructor-alias.output.md | 4 -- .../update-type-delete-constructor.output.md | 4 -- .../update-type-no-op-record.output.md | 4 -- ...ate-type-stray-constructor-alias.output.md | 4 -- ...type-turn-non-record-into-record.output.md | 4 -- 23 files changed, 27 insertions(+), 109 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs index 3473325bd1..fb43a5c716 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs @@ -128,19 +128,33 @@ handleUpdate2 = do pure (pped, bigUf) - -- - typecheck it - Cli.respond Output.UpdateStartTypechecking - parsingEnv <- makeParsingEnv currentPath namesIncludingLibdeps - prettyParseTypecheck bigUf pped parsingEnv >>= \case - Left prettyUf -> do - Cli.Env {isTranscript} <- ask - maybePath <- if isTranscript then pure Nothing else Just . fst <$> Cli.expectLatestFile - Cli.respond (Output.DisplayDefinitionsString maybePath prettyUf) - Cli.respond Output.UpdateTypecheckingFailure - Right tuf -> do - Cli.respond Output.UpdateTypecheckingSuccess - saveTuf (findCtorNames namesExcludingLibdeps ctorNames Nothing) tuf - Cli.respond Output.Success + -- If the new-unison-file-to-typecheck is the same as old-unison-file-that-we-already-typechecked, then don't bother + -- typechecking again. + secondTuf <- do + let smallUf = UF.discardTypes tuf + let noChanges = + and + [ UF.dataDeclarations smallUf == UF.dataDeclarations bigUf, + UF.effectDeclarations smallUf == UF.effectDeclarations bigUf, + UF.terms smallUf == UF.terms bigUf, -- no need to sort these, though it wouldn't hurt + UF.watches smallUf == UF.watches bigUf + ] + if noChanges + then pure tuf + else do + Cli.respond Output.UpdateStartTypechecking + parsingEnv <- makeParsingEnv currentPath namesIncludingLibdeps + secondTuf <- + prettyParseTypecheck bigUf pped parsingEnv & onLeftM \prettyUf -> do + Cli.Env {isTranscript} <- ask + maybePath <- if isTranscript then pure Nothing else Just . fst <$> Cli.expectLatestFile + Cli.respond (Output.DisplayDefinitionsString maybePath prettyUf) + Cli.returnEarly Output.UpdateTypecheckingFailure + Cli.respond Output.UpdateTypecheckingSuccess + pure secondTuf + + saveTuf (findCtorNames namesExcludingLibdeps ctorNames Nothing) secondTuf + Cli.respond Output.Success -- TODO: find a better module for this function, as it's used in a couple places prettyParseTypecheck :: diff --git a/unison-src/transcripts/addupdatemessages.output.md b/unison-src/transcripts/addupdatemessages.output.md index e42792022b..e514279d5f 100644 --- a/unison-src/transcripts/addupdatemessages.output.md +++ b/unison-src/transcripts/addupdatemessages.output.md @@ -140,10 +140,6 @@ Expected: `x` is now `2` and `X` is `Two`. UCM says the old definition was also Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. ``` diff --git a/unison-src/transcripts/fix-1381-excess-propagate.output.md b/unison-src/transcripts/fix-1381-excess-propagate.output.md index 0e52f4f5a0..f07217266b 100644 --- a/unison-src/transcripts/fix-1381-excess-propagate.output.md +++ b/unison-src/transcripts/fix-1381-excess-propagate.output.md @@ -26,10 +26,6 @@ a = "an update" Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. ``` diff --git a/unison-src/transcripts/fix1356.output.md b/unison-src/transcripts/fix1356.output.md index 5355a8da6c..6c87fb1657 100644 --- a/unison-src/transcripts/fix1356.output.md +++ b/unison-src/transcripts/fix1356.output.md @@ -72,10 +72,6 @@ Step 4: I add it and expect to see it Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .trunk> docs x diff --git a/unison-src/transcripts/merges.output.md b/unison-src/transcripts/merges.output.md index 6793dc45b3..2b9adb89a6 100644 --- a/unison-src/transcripts/merges.output.md +++ b/unison-src/transcripts/merges.output.md @@ -230,10 +230,6 @@ master.frobnicate n = n + 1 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view master.y diff --git a/unison-src/transcripts/move-namespace.output.md b/unison-src/transcripts/move-namespace.output.md index 22c548e2ef..2a45e515db 100644 --- a/unison-src/transcripts/move-namespace.output.md +++ b/unison-src/transcripts/move-namespace.output.md @@ -56,10 +56,6 @@ unique type a.T = T1 | T2 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. ``` @@ -151,10 +147,6 @@ b.termInB = 11 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. ``` @@ -247,10 +239,6 @@ b.termInB = 11 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .existing> move.namespace a b diff --git a/unison-src/transcripts/reset.output.md b/unison-src/transcripts/reset.output.md index c0d02a5d80..21308debb7 100644 --- a/unison-src/transcripts/reset.output.md +++ b/unison-src/transcripts/reset.output.md @@ -181,10 +181,6 @@ foo/main> update Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. foo/main> reset /topic diff --git a/unison-src/transcripts/update-ignores-lib-namespace.output.md b/unison-src/transcripts/update-ignores-lib-namespace.output.md index b9911ef0e1..2a4ddeacd4 100644 --- a/unison-src/transcripts/update-ignores-lib-namespace.output.md +++ b/unison-src/transcripts/update-ignores-lib-namespace.output.md @@ -51,10 +51,6 @@ foo = 200 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> names foo diff --git a/unison-src/transcripts/update-on-conflict.output.md b/unison-src/transcripts/update-on-conflict.output.md index 27b7088f8d..aaae8b31a1 100644 --- a/unison-src/transcripts/update-on-conflict.output.md +++ b/unison-src/transcripts/update-on-conflict.output.md @@ -88,10 +88,6 @@ x = 3 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .merged> view.patch diff --git a/unison-src/transcripts/update-term-aliases-in-different-ways.output.md b/unison-src/transcripts/update-term-aliases-in-different-ways.output.md index 0bfd5e3f09..7602194985 100644 --- a/unison-src/transcripts/update-term-aliases-in-different-ways.output.md +++ b/unison-src/transcripts/update-term-aliases-in-different-ways.output.md @@ -62,10 +62,6 @@ bar = 7 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view foo bar diff --git a/unison-src/transcripts/update-term-to-different-type.output.md b/unison-src/transcripts/update-term-to-different-type.output.md index fbc33721fe..177c0e55f0 100644 --- a/unison-src/transcripts/update-term-to-different-type.output.md +++ b/unison-src/transcripts/update-term-to-different-type.output.md @@ -51,10 +51,6 @@ foo = +5 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view foo diff --git a/unison-src/transcripts/update-term-with-alias.output.md b/unison-src/transcripts/update-term-with-alias.output.md index d809054b32..3183ef196a 100644 --- a/unison-src/transcripts/update-term-with-alias.output.md +++ b/unison-src/transcripts/update-term-with-alias.output.md @@ -57,10 +57,6 @@ foo = 6 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view foo bar diff --git a/unison-src/transcripts/update-term.output.md b/unison-src/transcripts/update-term.output.md index 96858cf1ba..eb3e720d81 100644 --- a/unison-src/transcripts/update-term.output.md +++ b/unison-src/transcripts/update-term.output.md @@ -51,10 +51,6 @@ foo = 6 Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view foo diff --git a/unison-src/transcripts/update-test-to-non-test.output.md b/unison-src/transcripts/update-test-to-non-test.output.md index 50b2a7591a..fef51e5669 100644 --- a/unison-src/transcripts/update-test-to-non-test.output.md +++ b/unison-src/transcripts/update-test-to-non-test.output.md @@ -64,10 +64,6 @@ After updating `foo` to not be a test, we expect `view` to not render it like a Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view foo diff --git a/unison-src/transcripts/update-type-add-constructor.output.md b/unison-src/transcripts/update-type-add-constructor.output.md index 58e0272061..003d987dcf 100644 --- a/unison-src/transcripts/update-type-add-constructor.output.md +++ b/unison-src/transcripts/update-type-add-constructor.output.md @@ -46,10 +46,6 @@ unique type Foo Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view Foo diff --git a/unison-src/transcripts/update-type-add-field.output.md b/unison-src/transcripts/update-type-add-field.output.md index a53241b264..9d5ddef1f7 100644 --- a/unison-src/transcripts/update-type-add-field.output.md +++ b/unison-src/transcripts/update-type-add-field.output.md @@ -43,10 +43,6 @@ unique type Foo = Bar Nat Nat Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view Foo diff --git a/unison-src/transcripts/update-type-add-new-record.output.md b/unison-src/transcripts/update-type-add-new-record.output.md index 99980ea0cb..14bb5f0cb8 100644 --- a/unison-src/transcripts/update-type-add-new-record.output.md +++ b/unison-src/transcripts/update-type-add-new-record.output.md @@ -22,10 +22,6 @@ unique type Foo = { bar : Nat } Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view Foo diff --git a/unison-src/transcripts/update-type-add-record-field.output.md b/unison-src/transcripts/update-type-add-record-field.output.md index 0581715d28..7fb4a3fac5 100644 --- a/unison-src/transcripts/update-type-add-record-field.output.md +++ b/unison-src/transcripts/update-type-add-record-field.output.md @@ -58,10 +58,6 @@ unique type Foo = { bar : Nat, baz : Int } Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view Foo diff --git a/unison-src/transcripts/update-type-constructor-alias.output.md b/unison-src/transcripts/update-type-constructor-alias.output.md index 800561097b..76abbe99a8 100644 --- a/unison-src/transcripts/update-type-constructor-alias.output.md +++ b/unison-src/transcripts/update-type-constructor-alias.output.md @@ -49,10 +49,6 @@ Bug: we leave `Foo.BarAlias` in the namespace with a nameless decl. Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> find.verbose diff --git a/unison-src/transcripts/update-type-delete-constructor.output.md b/unison-src/transcripts/update-type-delete-constructor.output.md index 9cc293a284..d5a0c69810 100644 --- a/unison-src/transcripts/update-type-delete-constructor.output.md +++ b/unison-src/transcripts/update-type-delete-constructor.output.md @@ -46,10 +46,6 @@ unique type Foo Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view Foo diff --git a/unison-src/transcripts/update-type-no-op-record.output.md b/unison-src/transcripts/update-type-no-op-record.output.md index 3b5ab56172..d47393ea7e 100644 --- a/unison-src/transcripts/update-type-no-op-record.output.md +++ b/unison-src/transcripts/update-type-no-op-record.output.md @@ -35,10 +35,6 @@ Bug: this no-op update should (of course) succeed. Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. ``` diff --git a/unison-src/transcripts/update-type-stray-constructor-alias.output.md b/unison-src/transcripts/update-type-stray-constructor-alias.output.md index 351e4582e3..a381642cce 100644 --- a/unison-src/transcripts/update-type-stray-constructor-alias.output.md +++ b/unison-src/transcripts/update-type-stray-constructor-alias.output.md @@ -49,10 +49,6 @@ Bug: we leave `Stray.BarAlias` in the namespace with a nameless decl. Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> find.verbose diff --git a/unison-src/transcripts/update-type-turn-non-record-into-record.output.md b/unison-src/transcripts/update-type-turn-non-record-into-record.output.md index 5123967d69..08e3f0a379 100644 --- a/unison-src/transcripts/update-type-turn-non-record-into-record.output.md +++ b/unison-src/transcripts/update-type-turn-non-record-into-record.output.md @@ -49,10 +49,6 @@ unique type Foo = { bar : Nat } Okay, I'm searching the branch for code that needs to be updated... - That's done. Now I'm making sure everything typechecks... - - Everything typechecks, so I'm saving the results... - Done. .> view Foo From 6ffe0fa34ed906fa685651a0e669c13f7ca97704 Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Wed, 29 Nov 2023 16:11:32 -0500 Subject: [PATCH 2/2] make same-unison-file check go faster --- .../src/Unison/Codebase/Editor/HandleInput/Update2.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs index fb43a5c716..e7a8dbdbfb 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs @@ -134,10 +134,10 @@ handleUpdate2 = do let smallUf = UF.discardTypes tuf let noChanges = and - [ UF.dataDeclarations smallUf == UF.dataDeclarations bigUf, - UF.effectDeclarations smallUf == UF.effectDeclarations bigUf, - UF.terms smallUf == UF.terms bigUf, -- no need to sort these, though it wouldn't hurt - UF.watches smallUf == UF.watches bigUf + [ Map.size (UF.dataDeclarations smallUf) == Map.size (UF.dataDeclarations bigUf), + Map.size (UF.effectDeclarations smallUf) == Map.size (UF.effectDeclarations bigUf), + length @[] (UF.terms smallUf) == length @[] (UF.terms bigUf), + Map.size (UF.watches smallUf) == Map.size (UF.watches bigUf) ] if noChanges then pure tuf