|
|
@ -302,10 +302,10 @@ comp a psi@phi u incA0@(compOutS (a @@ VI1) phi (u @@ VI1 @@ VItIsOne) -> a0) = |
|
|
|
VNe (HData False _) args -> |
|
|
|
case force a0 of |
|
|
|
VNe (HCon con_type con_name) con_args -> |
|
|
|
VNe (HCon con_type con_name) $ compConArgs (length args) (a @@) con_type con_args phi u |
|
|
|
VNe (HCon con_type con_name) $ compConArgs makeSetFiller (length args) (a @@) con_type con_args phi u |
|
|
|
_ -> VComp a phi u (VInc (a @@ VI0) phi a0) |
|
|
|
|
|
|
|
VNe (HData True _) args -> compHIT (length args) (a @@) phi u incA0 |
|
|
|
VNe (HData True name) args -> compHIT name (length args) (a @@) phi u incA0 |
|
|
|
|
|
|
|
VLam{} -> error $ "comp VLam " ++ show (prettyTm (quote a)) |
|
|
|
sys@VSystem{} -> error $ "comp VSystem: " ++ show (prettyTm (quote sys)) |
|
|
@ -328,50 +328,55 @@ forceAndGlue v = |
|
|
|
v@VGlueTy{} -> v |
|
|
|
y -> VGlueTy y VI1 (fun (const y)) (fun (const (idEquiv y))) |
|
|
|
|
|
|
|
compHIT :: HasCallStack => Int -> (NFEndp -> NFSort) -> NFEndp -> Value -> Value -> Value |
|
|
|
compHIT 0 a phi u a0 = |
|
|
|
case phi of |
|
|
|
compHIT :: HasCallStack => Name -> Int -> (NFEndp -> NFSort) -> NFEndp -> Value -> Value -> Value |
|
|
|
compHIT name n a phi u a0 = |
|
|
|
case force phi of |
|
|
|
VI1 -> u @@ VI1 @@ VItIsOne |
|
|
|
VI0 -> compOutS (a VI0) phi u a0 |
|
|
|
_ -> VHComp (a VI0) phi u a0 |
|
|
|
compHIT _ a phi u a0 = error $ unlines |
|
|
|
[ "*** TODO: composition for HIT: " |
|
|
|
, "domain = " ++ show (prettyTm (quote (zonk (fun a)))) |
|
|
|
, "phi = " ++ show (prettyTm (quote (zonk phi))) |
|
|
|
, "u = " ++ show (prettyTm (quote (zonk u))) |
|
|
|
, "a0 = " ++ show (prettyTm (quote (zonk a0))) |
|
|
|
] |
|
|
|
|
|
|
|
compConArgs :: Int -> (NFEndp -> Value) -> Value -> Seq.Seq Projection -> NFEndp -> Value -> Seq.Seq Projection |
|
|
|
compConArgs total_args fam = go total_args where |
|
|
|
VI0 -> transHit name a VI0 (compOutS (a VI0) phi u a0) |
|
|
|
x -> go n a x u a0 |
|
|
|
where |
|
|
|
go 0 a phi u a0 = VHComp (a VI0) phi u a0 |
|
|
|
go _ a phi u a0 = VHComp (a VI1) phi (system \i n -> squeezeHit name a VI0 (\i -> u @@ i @@ n) i) (transHit name a VI0 (compOutS (a VI1) phi (u @@ VI1 @@ VItIsOne) a0)) |
|
|
|
|
|
|
|
compConArgs :: (Name -> Int -> Value -> t1 -> t2 -> Value -> Value) |
|
|
|
-> Int |
|
|
|
-> (Value -> Value) |
|
|
|
-> Value |
|
|
|
-> Seq.Seq Projection |
|
|
|
-> t1 -> t2 |
|
|
|
-> Seq.Seq Projection |
|
|
|
compConArgs makeFiller total_args fam = go total_args where |
|
|
|
go _ _ Seq.Empty _ _ = Seq.Empty |
|
|
|
go nargs (VPi p dom (Closure _ rng)) (PApp p' y Seq.:<| xs) phi u |
|
|
|
| nargs > 0 = assert (p == p') $ go (nargs - 1) (rng (smuggle (fun (\i -> nthArg (total_args - nargs) (fam i))))) xs phi u |
|
|
|
| nargs > 0 = assert (p == p') $ |
|
|
|
PApp p' (nthArg (total_args - nargs) (fam VI1)) Seq.:<| go (nargs - 1) (rng (smuggle (fun (\i -> nthArg (total_args - nargs) (fam i))))) xs phi u |
|
|
|
| otherwise = assert (p == p') $ |
|
|
|
let fill = makeFiller nargs dom phi u y |
|
|
|
let fill = makeFiller typeArgument nargs dom phi u y |
|
|
|
in PApp p' (fill @@ VI1) Seq.:<| go (nargs - 1) (rng fill) xs phi u |
|
|
|
go _ _ _ _ _ = error $ "invalid constructor" |
|
|
|
|
|
|
|
nthArg i (VNe hd s) = |
|
|
|
case s Seq.!? i of |
|
|
|
Just (PApp _ t) -> t |
|
|
|
_ -> error $ "invalid " ++ show i ++ "th argument to data type " ++ show hd |
|
|
|
nthArg i (VSystem vs) = VSystem (fmap (nthArg i) vs) |
|
|
|
nthArg i xs = error $ "can't get " ++ show i ++ "th argument of " ++ show (prettyTm (quote xs)) |
|
|
|
|
|
|
|
makeFiller nth (VNe (HData _ n') args) phi u a0 |
|
|
|
| n' == typeArgument = |
|
|
|
fun $ fill (makeDomain args) phi (system \i is1 -> nthArg nth (u @@ i @@ is1) ) a0 |
|
|
|
makeFiller _ _ _ _ a0 = fun (const a0) |
|
|
|
|
|
|
|
makeDomain (PApp _ x Seq.:<| xs) = fun \i -> foldl (\t (~(PApp _ x)) -> t @@ (x @@ i)) (x @@ i) xs |
|
|
|
makeDomain _ = error "somebody smuggled something that smells" |
|
|
|
|
|
|
|
smuggle x = VNe (HData False typeArgument) (Seq.singleton (PApp P.Ex x)) |
|
|
|
|
|
|
|
typeArgument = unsafePerformIO newName |
|
|
|
{-# NOINLINE typeArgument #-} |
|
|
|
|
|
|
|
makeSetFiller :: Name -> Int -> Value -> NFEndp -> Value -> Value -> Value |
|
|
|
makeSetFiller typeArgument nth (VNe (HData _ n') args) phi u a0 |
|
|
|
| n' == typeArgument = |
|
|
|
fun $ fill (makeDomain args) phi (system \i is1 -> nthArg nth (u @@ i @@ is1) ) a0 |
|
|
|
where |
|
|
|
makeDomain (PApp _ x Seq.:<| xs) = fun \i -> foldl (\t (~(PApp _ x)) -> t @@ (x @@ i)) (x @@ i) xs |
|
|
|
makeDomain _ = error "somebody smuggled something that smells" |
|
|
|
makeSetFiller _ _ _ _ _ a0 = fun (const a0) |
|
|
|
|
|
|
|
nthArg :: Int -> Value -> Value |
|
|
|
nthArg i (VNe hd s) = |
|
|
|
case s Seq.!? i of |
|
|
|
Just (PApp _ t) -> t |
|
|
|
_ -> error $ "invalid " ++ show i ++ "th argument to data type " ++ show hd |
|
|
|
nthArg i (VSystem vs) = VSystem (fmap (nthArg i) vs) |
|
|
|
nthArg i xs = error $ "can't get " ++ show i ++ "th argument of " ++ show (prettyTm (quote xs)) |
|
|
|
|
|
|
|
compOutS :: HasCallStack => NFSort -> NFEndp -> Value -> Value -> Value |
|
|
|
compOutS a b c d = compOutS a b c (force d) where |
|
|
|
compOutS _ _hi _0 vl@VComp{} = vl |
|
|
@ -462,6 +467,43 @@ contr a aC phi u = |
|
|
|
transp :: (NFEndp -> Value) -> Value -> Value |
|
|
|
transp line a0 = comp (fun line) VI0 (system \_ _ -> VSystem mempty) (VInc (line VI0) VI0 a0) |
|
|
|
|
|
|
|
gtrans :: (NFEndp -> Value) -> NFEndp -> Value -> Value |
|
|
|
gtrans line phi a0 = comp (fun line) phi (system \_ _ -> mkVSystem (Map.singleton phi a0)) (VInc (line VI0) VI0 a0) |
|
|
|
|
|
|
|
transHit :: Name -> (NFEndp -> Value) -> NFEndp -> Value -> Value |
|
|
|
transHit name line phi (VHComp _ psi u u0) = VHComp (line VI1) psi (system \i j -> transHit name line phi (u @@ i @@ j)) (transHit name line phi u0) |
|
|
|
transHit name line phi (VNe (HCon con_type con_name) spine) | ourType = x' where |
|
|
|
x' = VNe (HCon con_type con_name) $ compConArgs (makeTransFiller name) nargs line con_type spine phi () |
|
|
|
(_, VNe hd (length -> nargs)) = unPi con_type |
|
|
|
ourType = case hd of |
|
|
|
HData True n' -> n' == name |
|
|
|
_ -> False |
|
|
|
|
|
|
|
transHit name line phi (VNe (HPCon sys con_type con_name) spine) | ourType = x' where |
|
|
|
x' = VNe (HPCon (mapVSystem rec sys) con_type con_name) $ compConArgs (makeTransFiller name) nargs line con_type spine phi () |
|
|
|
rec = transHit name line phi |
|
|
|
(_, VNe hd (length -> nargs)) = unPi con_type |
|
|
|
ourType = case hd of |
|
|
|
HData True n' -> n' == name |
|
|
|
_ -> False |
|
|
|
|
|
|
|
transHit name line phi (VSystem xs) = mkVSystem (fmap (transHit name line phi) xs) |
|
|
|
transHit _ line phi a0 = gtrans line phi a0 |
|
|
|
|
|
|
|
fillHit :: Name -> (NFEndp -> Value) -> NFEndp -> Value -> NFEndp -> Value |
|
|
|
fillHit name a phi a0 i = transHit name (\j -> a (iand i j)) (phi `ior` inot i) a0 where |
|
|
|
|
|
|
|
squeezeHit :: Name -> (NFEndp -> Value) -> NFEndp -> (NFEndp -> Value) -> NFEndp -> Value |
|
|
|
squeezeHit name a phi x i = transHit name (\j -> a (ior i j)) (phi `ior` i) (x i) |
|
|
|
|
|
|
|
makeTransFiller :: Name -> Name -> p -> Value -> NFEndp -> () -> Value -> Value |
|
|
|
makeTransFiller thedata typeArgument _ (VNe (HData _ n') args) phi () a0 |
|
|
|
| n' == typeArgument = fun (fillHit thedata (makeDomain args) phi a0) |
|
|
|
where |
|
|
|
makeDomain (PApp _ x Seq.:<| xs) = \i -> foldl (\t (~(PApp _ x)) -> t @@ (x @@ i)) (x @@ i) xs |
|
|
|
makeDomain _ = error "somebody smuggled something that smells" |
|
|
|
makeTransFiller _ _ _ _ _ _ a0 = fun (const a0) |
|
|
|
|
|
|
|
makeEquiv :: Name -> Value -> Value |
|
|
|
makeEquiv var vne = VPair f $ fun \y -> VPair (fib y) (fun \u -> p (vProj1 u) (vProj2 u) y) |
|
|
|
where |
|
|
|