@@ -13,22 +13,23 @@ import Control.Monad ( mapM )
1313import Data.List ( foldl' )
1414import Data.Function ( (&) )
1515import Data.Bifunctor ( second )
16- import Data.Maybe ( isJust )
16+ import Data.Maybe ( isJust , mapMaybe )
1717import Data.Function ( applyWhen )
1818
1919import Agda.Syntax.Common ( unArg , Arg (Arg ) )
2020import Agda.Syntax.Internal
21+ import Agda.TypeChecking.Substitute ( absBody , TelV (theCore ), absApp )
22+ import Agda.TypeChecking.Telescope (telView )
2123import Agda.TypeChecking.Monad.Base ( TCM , MonadTCM (liftTCM ), Definition (.. ))
22- import Agda.Utils.Monad (ifM )
24+ import Agda.TypeChecking.Monad.Signature ( canonicalName )
25+ import Agda.TypeChecking.Telescope ( mustBePi )
26+ import Agda.Utils.Monad ( ifM )
2327
2428import qualified LambdaBox as LBox
2529import Agda2Lambox.Compile.Utils
2630import Agda2Lambox.Compile.Monad
2731import Agda.Compiler.Backend (HasConstInfo (getConstInfo ), Definition (Defn ), AddContext (addContext ))
2832import Agda.Utils (isDataOrRecDef , getInductiveParams , isArity , maybeUnfoldCopy )
29- import Agda.TypeChecking.Substitute (absBody , TelV (theCore ))
30- import Agda.TypeChecking.Telescope (telView )
31- import Agda.TypeChecking.Monad.Signature ( canonicalName )
3233
3334
3435-- | The kind of variables that are locally bound
@@ -113,11 +114,15 @@ compileType tvars = runC tvars . compileTypeC
113114compileTypeC :: Type -> C LBox. Type
114115compileTypeC = local (\ e -> e { insertVars = False }) . fmap snd . compileTopLevelTypeC
115116
116- compileElims :: Elims -> C [LBox. Type ]
117- compileElims = mapM \ case
118- Apply a -> fmap snd $ compileTypeTerm $ unArg a
119- Proj {} -> genericError " type-level projection elim not supported."
120- IApply {} -> genericError " type-level cubical path application not supported."
117+ compileElims :: Type -> Args -> C [LBox. Type ]
118+ compileElims _ [] = pure []
119+ compileElims ty (x: xs) = do
120+ (a, b) <- mustBePi ty
121+ rest <- compileElims (absApp b $ unArg x) xs
122+ first <- ifM (liftTCM $ isLogical a)
123+ (pure LBox. TBox )
124+ (fmap snd $ compileTypeTerm $ unArg x)
125+ pure (first : rest)
121126
122127getTypeVarInfo :: Dom Type -> TCM LBox. TypeVarInfo
123128getTypeVarInfo typ = do
@@ -164,8 +169,9 @@ compileTypeTerm = \case
164169 else if isDataOrRecDef def then do
165170 lift $ requireDef q
166171 ind <- liftTCM $ toInductive q
172+ let args = mapMaybe isApplyElim es
167173 ([] ,) . foldl' LBox. TApp (LBox. TInd ind)
168- <$> compileElims (take (getInductiveParams def) es )
174+ <$> compileElims defType (take (getInductiveParams def) args )
169175
170176 -- otherwise, it must have been compiled as a type scheme,
171177 -- and therefore is kept with all arguments.
@@ -175,9 +181,11 @@ compileTypeTerm = \case
175181 -- TODO(flupe): possibly merge the logic with the above for datatypes
176182 else do
177183 q <- liftTCM $ canonicalName q
184+ lift $ requireDef q
178185 let ts = qnameToKName q
186+ let args = mapMaybe isApplyElim es
179187 ([] ,) . foldl' LBox. TApp (LBox. TConst ts)
180- <$> compileElims es
188+ <$> compileElims defType args
181189
182190 Pi dom codom -> do
183191 let domType = unDom dom
0 commit comments