Skip to content

Commit 957ee53

Browse files
authored
Merge pull request #4870 from unisonweb/cp/diff-by-namespace
Updates for Share diffs feature
2 parents 373ccf3 + 5e0e70e commit 957ee53

File tree

9 files changed

+25
-12
lines changed

9 files changed

+25
-12
lines changed

parser-typechecker/src/Unison/Builtin.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module Unison.Builtin
1616
typeOf,
1717
typeLookup,
1818
termRefTypes,
19+
termRefTypeReferences,
1920
)
2021
where
2122

@@ -320,14 +321,17 @@ termNameRefs = Map.mapKeys Name.unsafeParseText $ foldl' go mempty (stripVersion
320321
"tried to alias `" <> r <> "` before it was declared."
321322
Just t -> Map.insert name t m
322323

323-
termRefTypes :: Map R.Reference Type
324+
termRefTypes :: Map R.TermReference Type
324325
termRefTypes = foldl' go mempty builtinsSrc
325326
where
326327
go m = \case
327328
B r t -> Map.insert (R.Builtin r) t m
328329
D r t -> Map.insert (R.Builtin r) t m
329330
_ -> m
330331

332+
termRefTypeReferences :: Map R.TermReference R.TypeReference
333+
termRefTypeReferences = H.typeToReference <$> termRefTypes
334+
331335
typeOf :: a -> (Type -> a) -> R.Reference -> a
332336
typeOf a f r = maybe a f (Map.lookup r termRefTypes)
333337

parser-typechecker/src/Unison/Builtin/Decls.hs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Unison.ConstructorType qualified as CT
1212
import Unison.DataDeclaration (DataDeclaration (..), Modifier (Structural, Unique))
1313
import Unison.DataDeclaration qualified as DD
1414
import Unison.DataDeclaration.ConstructorId (ConstructorId)
15-
import Unison.Hashing.V2.Convert (hashDataDecls)
15+
import Unison.Hashing.V2.Convert (hashDataDecls, typeToReference)
1616
import Unison.Pattern qualified as Pattern
1717
import Unison.Reference (Reference)
1818
import Unison.Reference qualified as Reference
@@ -46,7 +46,7 @@ pairRef = lookupDeclRef "Tuple"
4646
optionalRef = lookupDeclRef "Optional"
4747
eitherRef = lookupDeclRef "Either"
4848

49-
testResultRef, linkRef, docRef, ioErrorRef, stdHandleRef :: Reference
49+
testResultRef, testResultListRef, linkRef, docRef, ioErrorRef, stdHandleRef :: Reference
5050
failureRef, ioFailureRef, tlsFailureRef, arrayFailureRef :: Reference
5151
cryptoFailureRef :: Reference
5252
exceptionRef, tlsSignedCertRef, tlsPrivateKeyRef :: Reference
@@ -57,6 +57,9 @@ isTestRef = lookupDeclRef "IsTest"
5757

5858
testResultRef = lookupDeclRef "Test.Result"
5959

60+
-- Reference for [Test.Result]
61+
testResultListRef = typeToReference @Symbol (testResultListType ())
62+
6063
linkRef = lookupDeclRef "Link"
6164

6265
docRef = lookupDeclRef "Doc"
@@ -723,7 +726,7 @@ pattern LinkType ty <- Term.App' (Term.Constructor' (ConstructorReference LinkRe
723726
unitType,
724727
pairType,
725728
optionalType,
726-
testResultType,
729+
testResultListType,
727730
eitherType,
728731
ioErrorType,
729732
fileModeType,
@@ -739,7 +742,7 @@ unitType a = Type.ref a unitRef
739742
-- used for the type of the argument to force a thunk
740743
thunkArgType = unitType
741744
pairType a = Type.ref a pairRef
742-
testResultType a = Type.app a (Type.list a) (Type.ref a testResultRef)
745+
testResultListType a = Type.app a (Type.list a) (Type.ref a testResultRef)
743746
optionalType a = Type.ref a optionalRef
744747
eitherType a = Type.ref a eitherRef
745748
ioErrorType a = Type.ref a ioErrorRef

parser-typechecker/src/Unison/Codebase/MainTerm.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,4 @@ builtinIOTestTypes a =
8181
)
8282
where
8383
delayed = Type.arrow a (Type.ref a DD.unitRef)
84-
delayedResultWithEffects es = delayed (Type.effect a es (DD.testResultType a))
84+
delayedResultWithEffects es = delayed (Type.effect a es (DD.testResultListType a))

parser-typechecker/src/Unison/UnisonFile.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ typecheckingTerm uf =
110110
bindings =
111111
terms uf <> testWatches <> watchesOfOtherKinds TestWatch uf
112112
-- we make sure each test has type Test.Result
113-
f w = let wa = ABT.annotation w in Term.ann wa w (DD.testResultType wa)
113+
f w = let wa = ABT.annotation w in Term.ann wa w (DD.testResultListType wa)
114114
testWatches = map (second f) $ watchesOfKind TestWatch uf
115115

116116
-- backwards compatibility with the old data type

unison-cli/src/Unison/Codebase/Editor/HandleInput/ShowDefinition.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ showDefinitions outputLoc pped terms types misses = do
5454
Cli.respond $ DisplayDefinitions renderedCodePretty
5555
Just fp -> do
5656
-- We build an 'isTest' check to prepend "test>" to tests in a scratch file.
57-
testRefs <- Cli.runTransaction (Codebase.filterTermsByReferenceIdHavingType codebase (DD.testResultType mempty) (Map.keysSet terms & Set.mapMaybe Reference.toId))
57+
testRefs <- Cli.runTransaction (Codebase.filterTermsByReferenceIdHavingType codebase (DD.testResultListType mempty) (Map.keysSet terms & Set.mapMaybe Reference.toId))
5858
let isTest r = Set.member r testRefs
5959
let isSourceFile = True
6060
let renderedCodePretty = renderCodePretty pped isSourceFile isTest terms types

unison-cli/src/Unison/Codebase/Editor/HandleInput/Tests.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ handleTest :: TestInput -> Cli ()
6060
handleTest TestInput {includeLibNamespace, showFailures, showSuccesses} = do
6161
Cli.Env {codebase} <- ask
6262

63-
testRefs <- findTermsOfTypes codebase includeLibNamespace (NESet.singleton (DD.testResultType mempty))
63+
testRefs <- findTermsOfTypes codebase includeLibNamespace (NESet.singleton (DD.testResultListType mempty))
6464

6565
cachedTests <-
6666
Map.fromList <$> Cli.runTransaction do

unison-cli/src/Unison/Codebase/Editor/HandleInput/Update2.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ addDefinitionsToUnisonFile abort codebase doFindCtorNames (terms, types) =
310310
Set.fromList [v | (v, _, _) <- uf.terms]
311311
<> foldMap (\x -> Set.fromList [v | (v, _, _) <- x]) uf.watches
312312

313-
isTest = Typechecker.isEqual (Decls.testResultType mempty)
313+
isTest = Typechecker.isEqual (Decls.testResultListType mempty)
314314

315315
-- given a dependent hash, include that component in the scratch file
316316
-- todo: wundefined: cut off constructor name prefixes

unison-share-api/src/Unison/Server/Backend.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ getTermTag codebase r sig = do
454454
-- A term is a test if it has the type [test.Result]
455455
let isTest = case sig of
456456
Just t ->
457-
Typechecker.isEqual t (Decls.testResultType mempty)
457+
Typechecker.isEqual t (Decls.testResultListType mempty)
458458
Nothing -> False
459459
constructorType <- case r of
460460
V2Referent.Ref {} -> pure Nothing

unison-share-api/src/Unison/Server/Orphans.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import Unison.ShortHash qualified as SH
3939
import Unison.Syntax.HashQualified qualified as HQ (parseText)
4040
import Unison.Syntax.HashQualified' qualified as HQ' (parseText)
4141
import Unison.Syntax.Name qualified as Name (parseTextEither, toText)
42-
import Unison.Syntax.NameSegment qualified as NameSegment (toEscapedText)
42+
import Unison.Syntax.NameSegment qualified as NameSegment
4343
import Unison.Util.Pretty (Width (..))
4444

4545
instance ToJSON Hash where
@@ -173,6 +173,12 @@ instance ToJSONKey Name where
173173
instance ToSchema Name where
174174
declareNamedSchema _ = declareNamedSchema (Proxy @Text)
175175

176+
instance ToJSON NameSegment where
177+
toJSON = toJSON . NameSegment.toEscapedText
178+
179+
instance ToJSONKey NameSegment where
180+
toJSONKey = contramap NameSegment.toEscapedText (toJSONKey @Text)
181+
176182
deriving anyclass instance ToParamSchema ShortCausalHash
177183

178184
instance ToParamSchema ShortHash where

0 commit comments

Comments
 (0)