don't hydrate twice, and hyrate lca defns too

This commit is contained in:
Mitchell Rosen 2024-08-05 12:10:16 -04:00
parent 325e4ee4de
commit 565eb6625f
3 changed files with 36 additions and 21 deletions

View File

@ -255,8 +255,8 @@ doMerge info = do
ThreeWay.forgetLca defns3
-- Hydrate
hydratedDefns2 ::
Merge.TwoWay
hydratedDefns3 ::
Merge.ThreeWay
( DefnsF
(Map Name)
(TermReferenceId, (Term Symbol Ann, Type Symbol Ann))
@ -270,15 +270,16 @@ doMerge info = do
)
( let f = Map.mapMaybe Referent.toTermReferenceId . BiMultimap.range
g = Map.mapMaybe Reference.toId . BiMultimap.range
in bimap f g <$> ThreeWay.forgetLca defns3
in bimap f g <$> defns3
)
-- Make one big constructor count lookup for Alice+Bob's type decls
-- Make one big constructor count lookup for all type decls
let numConstructors :: Map TypeReferenceId Int
numConstructors =
Map.empty
& f (Map.elems hydratedDefns2.alice.types)
& f (Map.elems hydratedDefns2.bob.types)
& f (Map.elems hydratedDefns3.alice.types)
& f (Map.elems hydratedDefns3.bob.types)
& f (Map.elems hydratedDefns3.lca.types)
where
f :: [(TypeReferenceId, Decl Symbol Ann)] -> Map TypeReferenceId Int -> Map TypeReferenceId Int
f types acc =
@ -316,11 +317,11 @@ doMerge info = do
{ terms =
foldMap
(List.foldl' (\acc (ref, (term, _)) -> Map.insert ref term acc) Map.empty . Map.elems . (.terms))
hydratedDefns2,
hydratedDefns3,
types =
foldMap
(List.foldl' (\acc (ref, typ) -> Map.insert ref typ acc) Map.empty . Map.elems . (.types))
hydratedDefns2
hydratedDefns3
}
liftIO (debugFunctions.debugDiffs diffs)
@ -349,8 +350,9 @@ doMerge info = do
-- aren't conflicts, or else for manual conflict resolution without a typechecking step, if there are)
let soloUpdatesAndDeletes = Unconflicts.soloUpdatesAndDeletes unconflicts
let coreDependencies = identifyCoreDependencies defns2 conflicts soloUpdatesAndDeletes
dependents0 <- Cli.runTransaction (for ((,) <$> defns2 <*> coreDependencies) (uncurry getNamespaceDependentsOf2))
let dependents = filterDependents conflicts soloUpdatesAndDeletes dependents0
dependents <- do
dependents0 <- Cli.runTransaction (for ((,) <$> defns2 <*> coreDependencies) (uncurry getNamespaceDependentsOf2))
pure (filterDependents conflicts soloUpdatesAndDeletes dependents0)
liftIO (debugFunctions.debugDependents dependents)
@ -381,11 +383,19 @@ doMerge info = do
suffixifier = PPE.suffixifyByName (fold defnsNames <> libdepsNames)
let ppes = mkPpes (defnsToNames <$> defns2) (Branch.toNames mergedLibdeps)
hydratedThings <- do
Cli.runTransaction do
for ((,) <$> conflicts <*> dependents) \(conflicts1, dependents1) ->
let hydrate = hydrateDefns (Codebase.unsafeGetTermComponent env.codebase) Operations.expectDeclComponent
in (,) <$> hydrate conflicts1 <*> hydrate dependents1
let hydratedThings ::
Merge.TwoWay
( DefnsF (Map Name) (TermReferenceId, (Term Symbol Ann, Type Symbol Ann)) (TypeReferenceId, Decl Symbol Ann),
DefnsF (Map Name) (TermReferenceId, (Term Symbol Ann, Type Symbol Ann)) (TypeReferenceId, Decl Symbol Ann)
)
hydratedThings =
( \as bs cs ->
let f xs ys = xs `Map.restrictKeys` Map.keysSet ys
in (zipDefnsWith f f as bs, zipDefnsWith f f as cs)
)
<$> ThreeWay.forgetLca hydratedDefns3
<*> conflicts
<*> dependents
let (renderedConflicts, renderedDependents) =
unzip $

View File

@ -47,6 +47,7 @@ import Unison.Util.Defns (Defns (..), DefnsF2, DefnsF3, zipDefnsWith)
-- where each name is paired with its diff-op (added, deleted, or updated), relative to the LCA between Alice and Bob's
-- branches. If the hash of a name did not change, it will not appear in the map.
nameBasedNamespaceDiff ::
HasCallStack =>
TwoWay DeclNameLookup ->
PartialDeclNameLookup ->
ThreeWay (Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name)) ->
@ -88,6 +89,7 @@ diffHashedNamespaceDefns =
-- Syntactic hashing
synhashLcaDefns ::
HasCallStack =>
PrettyPrintEnv ->
PartialDeclNameLookup ->
Defns (BiMultimap Referent Name) (BiMultimap TypeReference Name) ->
@ -119,6 +121,7 @@ synhashLcaDefns ppe declNameLookup defns hydratedDefns =
Just names -> synhashDerivedDecl ppe hydratedDefns.types names name ref
synhashDefns ::
HasCallStack =>
PrettyPrintEnv ->
Defns (Map TermReferenceId (Term Symbol Ann)) (Map TypeReferenceId (Decl Symbol Ann)) ->
DeclNameLookup ->
@ -145,6 +148,7 @@ synhashDefns ppe hydratedDefns declNameLookup =
synhashDerivedDecl ppe hydratedDefns.types (DeclNameLookup.expectConstructorNames declNameLookup name) name ref
synhashDerivedDecl ::
HasCallStack =>
PrettyPrintEnv ->
Map TypeReferenceId (Decl Symbol Ann) ->
[Name] ->
@ -157,12 +161,13 @@ synhashDerivedDecl ppe declsById names name ref =
& DataDeclaration.setConstructorNames (map Name.toVar names)
& Synhash.synhashDerivedDecl ppe name
synhashTermReference :: PrettyPrintEnv -> Map TermReferenceId (Term Symbol Ann) -> TermReference -> Hash
synhashTermReference :: HasCallStack => PrettyPrintEnv -> Map TermReferenceId (Term Symbol Ann) -> TermReference -> Hash
synhashTermReference ppe termsById = \case
ReferenceBuiltin builtin -> Synhash.synhashBuiltinTerm builtin
ReferenceDerived ref -> Synhash.synhashDerivedTerm ppe (expectTerm ref termsById)
synhashDefnsWith ::
HasCallStack =>
(Name -> term -> Hash) ->
(Name -> typ -> Hash) ->
Defns (BiMultimap term Name) (BiMultimap typ Name) ->
@ -194,13 +199,13 @@ deepNamespaceDefinitionsToPpe Defns {terms, types} =
------------------------------------------------------------------------------------------------------------------------
-- Looking up terms and decls that we expect to be there
expectTerm :: TermReferenceId -> Map TermReferenceId (Term Symbol Ann) -> Term Symbol Ann
expectTerm :: HasCallStack => TermReferenceId -> Map TermReferenceId (Term Symbol Ann) -> Term Symbol Ann
expectTerm ref termsById =
case Map.lookup ref termsById of
Nothing -> error (reportBug "E488229" ("term ref " ++ show ref ++ " not found in map " ++ show termsById))
Just term -> term
expectDecl :: TypeReferenceId -> Map TypeReferenceId (Decl Symbol Ann) -> Decl Symbol Ann
expectDecl :: HasCallStack => TypeReferenceId -> Map TypeReferenceId (Decl Symbol Ann) -> Decl Symbol Ann
expectDecl ref declsById =
case Map.lookup ref declsById of
Nothing -> error (reportBug "E663160" ("type ref " ++ show ref ++ " not found in map " ++ show declsById))

View File

@ -1335,9 +1335,9 @@ project/alice> merge /bob
Sorry, I wasn't able to perform the merge:
There's a merge conflict on MyNat, but it's a builtin on one
or both branches. I can't yet handle merge conflicts involving
builtins.
There's a merge conflict on type MyNat, but it's a builtin on
one or both branches. I can't yet handle merge conflicts
involving builtins.
Please eliminate this conflict by updating one branch or the
other, making MyNat the same on both branches, or making