@@ -1047,6 +1047,18 @@ mutual
10471047 unifyBothApps mode loc env xfc fx ax yfc fy ay
10481048 = unifyApp False mode loc env xfc fx ax (NApp yfc fy ay)
10491049
1050+ unifyPiInfo : {auto c : Ref Ctxt Defs} ->
1051+ {auto u : Ref UST UState} ->
1052+ {vars : _} ->
1053+ UnifyInfo -> FC -> Env Term vars ->
1054+ PiInfo (Closure vars) -> PiInfo (Closure vars) ->
1055+ Core (Maybe UnifyResult)
1056+ unifyPiInfo mode loc env Explicit Explicit = pure $ Just success
1057+ unifyPiInfo mode loc env Implicit Implicit = pure $ Just success
1058+ unifyPiInfo mode loc env AutoImplicit AutoImplicit = pure $ Just success
1059+ unifyPiInfo mode loc env (DefImplicit x) (DefImplicit y) = Just <$> unify mode loc env x y
1060+ unifyPiInfo mode loc env _ _ = pure Nothing
1061+
10501062 unifyBothBinders : {auto c : Ref Ctxt Defs} ->
10511063 {auto u : Ref UST UState} ->
10521064 {vars : _} ->
@@ -1058,65 +1070,70 @@ mutual
10581070 Core UnifyResult
10591071 unifyBothBinders mode loc env xfc x (Pi fcx cx ix tx) scx yfc y (Pi fcy cy iy ty) scy
10601072 = do defs <- get Ctxt
1073+ let err = convertError loc env
1074+ (NBind xfc x (Pi fcx cx ix tx) scx)
1075+ (NBind yfc y (Pi fcy cy iy ty) scy)
10611076 if cx /= cy
1062- then convertError loc env
1063- ( NBind xfc x ( Pi fcx cx ix tx) scx)
1064- ( NBind yfc y ( Pi fcy cy iy ty) scy)
1065- else
1066- do empty <- clearDefs defs
1067- tx' <- quote empty env tx
1068- logC " unify.binder " 10 $
1069- ( do ty' <- quote empty env ty
1070- pure ( " Unifying arg types " ++ show tx' ++ " and " ++ show ty'))
1071- ct <- unify (lower mode) loc env tx ty
1072- xn <- genVarName " x "
1073- let env' : Env Term (x :: _ )
1074- = Pi fcy cy Explicit tx' :: env
1075- case constraints ct of
1076- [] => -- No constraints, check the scope
1077- do tscx <- scx defs (toClosure defaultOpts env (Ref loc Bound xn))
1078- tscy <- scy defs (toClosure defaultOpts env ( Ref loc Bound xn))
1079- tmx <- quote empty env tscx
1080- tmy <- quote empty env tscy
1081- unify (lower mode) loc env'
1082- (refsToLocals (Add x xn None ) tmx )
1083- (refsToLocals ( Add x xn None ) tmy )
1084- cs => -- Constraints, make new guarded constant
1085- do txtm <- quote empty env tx
1086- tytm <- quote empty env ty
1087- c <- newConstant loc erased env
1088- (Bind xfc x (Lam fcy cy Explicit txtm) (Local xfc Nothing _ First ))
1089- (Bind xfc x (Pi fcy cy Explicit txtm)
1090- (weaken tytm)) cs
1091- tscx <- scx defs (toClosure defaultOpts env (Ref loc Bound xn))
1092- tscy <- scy defs (toClosure defaultOpts env (App loc c (Ref loc Bound xn)))
1093- tmx <- quote empty env tscx
1094- tmy <- quote empty env tscy
1095- cs' <- unify (lower mode) loc env'
1096- (refsToLocals (Add x xn None ) tmx)
1097- (refsToLocals (Add x xn None ) tmy)
1098- pure (union ct cs')
1077+ then err
1078+ else do Just ci <- unifyPiInfo (lower mode) loc env ix iy
1079+ | Nothing => err
1080+ empty <- clearDefs defs
1081+ tx' <- quote empty env tx
1082+ logC " unify.binder " 10 $
1083+ ( do ty' <- quote empty env ty
1084+ pure ( " Unifying arg types " ++ show tx' ++ " and " ++ show ty'))
1085+ ct <- unify (lower mode) loc env tx ty
1086+ xn <- genVarName " x "
1087+ let env' : Env Term (x :: _ )
1088+ = Pi fcy cy Explicit tx' :: env
1089+ case constraints ct of
1090+ [] => -- No constraints, check the scope
1091+ do tscx <- scx defs (toClosure defaultOpts env ( Ref loc Bound xn))
1092+ tscy <- scy defs (toClosure defaultOpts env (Ref loc Bound xn))
1093+ tmx <- quote empty env tscx
1094+ tmy <- quote empty env tscy
1095+ cs <- unify (lower mode) loc env'
1096+ (refsToLocals ( Add x xn None ) tmx)
1097+ (refsToLocals (Add x xn None ) tmy )
1098+ pure (union ci cs )
1099+ cs => -- Constraints, make new guarded constant
1100+ do txtm <- quote empty env tx
1101+ tytm <- quote empty env ty
1102+ c <- newConstant loc erased env
1103+ (Bind xfc x (Lam fcy cy Explicit txtm) (Local xfc Nothing _ First ))
1104+ (Bind xfc x (Pi fcy cy Explicit txtm)
1105+ (weaken tytm)) cs
1106+ tscx <- scx defs (toClosure defaultOpts env (Ref loc Bound xn))
1107+ tscy <- scy defs (toClosure defaultOpts env (App loc c (Ref loc Bound xn)))
1108+ tmx <- quote empty env tscx
1109+ tmy <- quote empty env tscy
1110+ cs' <- unify (lower mode) loc env'
1111+ (refsToLocals (Add x xn None ) tmx)
1112+ (refsToLocals (Add x xn None ) tmy)
1113+ pure (union ci (union ct cs') )
10991114 unifyBothBinders mode loc env xfc x (Lam fcx cx ix tx) scx yfc y (Lam fcy cy iy ty) scy
11001115 = do defs <- get Ctxt
1116+ let err = convertError loc env
1117+ (NBind xfc x (Lam fcx cx ix tx) scx)
1118+ (NBind yfc y (Lam fcy cy iy ty) scy)
11011119 if cx /= cy
1102- then convertError loc env
1103- (NBind xfc x (Lam fcx cx ix tx) scx)
1104- (NBind yfc y (Lam fcy cy iy ty) scy)
1105- else
1106- do empty <- clearDefs defs
1107- ct <- unify (lower mode) loc env tx ty
1108- xn <- genVarName " x"
1109- txtm <- quote empty env tx
1110- let env' : Env Term (x :: _ )
1111- = Lam fcx cx Explicit txtm :: env
1112-
1113- tscx <- scx defs (toClosure defaultOpts env (Ref loc Bound xn))
1114- tscy <- scy defs (toClosure defaultOpts env (Ref loc Bound xn))
1115- tmx <- quote empty env tscx
1116- tmy <- quote empty env tscy
1117- cs' <- unify (lower mode) loc env' (refsToLocals (Add x xn None ) tmx)
1118- (refsToLocals (Add x xn None ) tmy)
1119- pure (union ct cs')
1120+ then err
1121+ else do empty <- clearDefs defs
1122+ Just ci <- unifyPiInfo (lower mode) loc env ix iy
1123+ | Nothing => err
1124+ ct <- unify (lower mode) loc env tx ty
1125+ xn <- genVarName " x"
1126+ txtm <- quote empty env tx
1127+ let env' : Env Term (x :: _ )
1128+ = Lam fcx cx Explicit txtm :: env
1129+
1130+ tscx <- scx defs (toClosure defaultOpts env (Ref loc Bound xn))
1131+ tscy <- scy defs (toClosure defaultOpts env (Ref loc Bound xn))
1132+ tmx <- quote empty env tscx
1133+ tmy <- quote empty env tscy
1134+ cs' <- unify (lower mode) loc env' (refsToLocals (Add x xn None ) tmx)
1135+ (refsToLocals (Add x xn None ) tmy)
1136+ pure (union ci (union ct cs'))
11201137
11211138 unifyBothBinders mode loc env xfc x bx scx yfc y by scy
11221139 = convertError loc env
0 commit comments