Visitar URL original
Comments/cleanup · agda/agda@41ff2c2 · GitHub
Skip to content

Commit 41ff2c2

Browse files
committed
Comments/cleanup
1 parent 4f2916f commit 41ff2c2

10 files changed

Lines changed: 58 additions & 32 deletions

File tree

‎src/full/Agda/Syntax/Internal.hs‎

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -482,10 +482,27 @@ data UnivSize
482482
| ULarge -- ^ @(Prop/Set/SSet)ωᵢ@.
483483
deriving stock (Eq, Show)
484484

485-
-- | Blocked dependency (i.e. free zero variable) check, used in 'PiSort'
485+
-- | Blocked dependency (i.e. free zero variable) check, used in 'PiSort'.
486+
--
486487
-- For efficiency, we track whether the codomain sort has actually changed.
487488
-- If it hasn't, we can avoid duplicating work.
488-
data BlockedDepCheck t = CodomainSortOld t | CodomainSortSame
489+
data BlockedDepCheck t
490+
= CodomainSortSame
491+
-- ^ The codomain sort has not changed, so we can just do the dependency
492+
-- check on the current codomain sort.
493+
| CodomainSortOld t
494+
-- ^ The codomain sort has changed, so we really need to do the dependency
495+
-- check on the original codomain sort.
496+
--
497+
-- E.g. see #5810: @∀ t → Set (ℓ t)@ has codomain sort @Set (lsuc (ℓ t))@
498+
-- but then after the substitution @ℓ ↦ λ _ → lzero@, the codomain sort
499+
-- becomes @Set (lsuc lzero)@, which is no longer dependent on @t@.
500+
-- To avoid a subject reduction problem, we have to remember that the
501+
-- codomain sort before the substitution was @Set (lsuc (ℓ t))@.
502+
--
503+
-- The old codomain sort lives in its original context. In an ideal world,
504+
-- we would store this context, but this does not appear very feasible
505+
-- (without a significant refactor).
489506
deriving (Show, Functor, Foldable, Traversable, Generic)
490507

491508
codomainSortOld :: t -> BlockedDepCheck t -> t
@@ -1639,7 +1656,7 @@ instance TermSize Sort where
16391656
LockUniv -> 1
16401657
LevelUniv -> 1
16411658
IntervalUniv -> 1
1642-
PiSort _ a s1 s2 -> 1 + tsize a + tsize s1 + tsize s2
1659+
PiSort _c a s1 s2 -> 1 + tsize a + tsize s1 + tsize s2
16431660
FunSort s1 s2 -> 1 + tsize s1 + tsize s2
16441661
UnivSort s -> 1 + tsize s
16451662
MetaS _ es -> 1 + tsize es
@@ -1853,7 +1870,7 @@ instance Pretty t => Pretty (Abs t) where
18531870

18541871
instance Pretty t => Pretty (BlockedDepCheck t) where
18551872
pretty (CodomainSortOld s) = "CodomainSortOld" <+> pretty s
1856-
pretty CodomainSortSame = "CodomainSortSame"
1873+
pretty CodomainSortSame = "CodomainSortSame"
18571874

18581875
instance (Pretty t, Pretty e) => Pretty (Dom' t e) where
18591876
pretty dom = pLock <+> pTac <+> pDom dom (pretty (getModality dom) <+> pretty (unDom dom))

‎src/full/Agda/Termination/TermCheck.hs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ instance ExtractCalls Sort where
830830
Univ _ t -> terUnguarded $ extract t -- no guarded levels
831831
-- We ignore calls in the blocked dependency check (these will vanish
832832
-- after the 'PiSort' reduces)
833-
PiSort _ a s1 s2 -> extract (a, s1, s2)
833+
PiSort _c a s1 s2 -> extract (a, s1, s2)
834834
FunSort s1 s2 -> extract (s1, s2)
835835
UnivSort s -> extract s
836836
MetaS x es -> return empty

‎src/full/Agda/TypeChecking/Conversion.hs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2065,8 +2065,8 @@ equalSort s1 s2 = do
20652065
CodomainSortSame -> funSortEquals propEnabled s s1 s2M blocker
20662066
CodomainSortOld s2Old -> liftReduce
20672067
(inLargeEnoughContext s2Old $ forceNonDepSort s2Old) >>= \case
2068-
(NotFree, _) -> funSortEquals propEnabled s s1 s2M blocker
2069-
(MaybeFree _, _) -> postpone
2068+
(NotFree, _) -> funSortEquals propEnabled s s1 s2M blocker
2069+
(MaybeFree _, _) -> postpone
20702070
-- Otherwise: postpone
20712071
| otherwise -> postpone
20722072

‎src/full/Agda/TypeChecking/Free/Generic.hs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ instance Free Sort where
211211
LockUniv -> ret $ mempty
212212
LevelUniv -> ret $ mempty
213213
IntervalUniv -> ret $ mempty
214-
PiSort c a s1 s2 -> ret $
214+
PiSort _c a s1 s2 -> ret $
215215
-- We ignore variables in the blocked dependency check
216216
underFlexRig (Flexible mempty) (freeVars $ unDom a) <>
217217
underFlexRig WeaklyRigid (freeVars (s1, s2))

‎src/full/Agda/TypeChecking/Free/Reduce.hs‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -240,12 +240,12 @@ instance ForceNotFree Sort where
240240
-- away without forceNotFreeR here.
241241
forceNotFree' s = expand \ret -> case s of
242242
Univ u l -> ret $ Univ u <$> forceNotFree' l
243-
PiSort a b c d -> ret do
243+
PiSort c a s1 s2 -> ret do
244244
-- We ignore variables in the blocked dependency check
245-
b <- underFlexRig (Flexible mempty) (forceNotFree' b)
246-
(!c, !d) <- underFlexRig WeaklyRigid
247-
((,) <$> forceNotFree' c <*> forceNotFree' d)
248-
pure $ PiSort a b c d
245+
a <- underFlexRig (Flexible mempty) (forceNotFree' a)
246+
(!s1, !s2) <- underFlexRig WeaklyRigid
247+
((,) <$> forceNotFree' s1 <*> forceNotFree' s2)
248+
pure $ PiSort c a s1 s2
249249
FunSort a b -> ret $ FunSort <$> forceNotFree' a <*> forceNotFree' b
250250
UnivSort s -> ret $ UnivSort <$> underFlexRig WeaklyRigid (forceNotFree' s)
251251
MetaS x es -> ret $ MetaS x <$> underFlexRig (Flexible (singleton x)) (forceNotFree' es)

‎src/full/Agda/TypeChecking/Irrelevance.hs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ instance UsableRelevance Sort where
155155
LockUniv -> return True
156156
LevelUniv -> return True
157157
IntervalUniv -> return True
158-
PiSort c a s1 s2 -> usableRel rel (a,s1,s2)
158+
PiSort _c a s1 s2 -> usableRel rel (a,s1,s2)
159159
FunSort s1 s2 -> usableRel rel (s1,s2)
160160
UnivSort s -> usableRel rel s
161161
MetaS x es -> usableRel rel es

‎src/full/Agda/TypeChecking/MetaVars/Occurs.hs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,7 @@ instance Occurs Sort where
770770
metaOccurs !m !s = do
771771
s <- instantiate s
772772
case s of
773-
PiSort _ a s1 s2 -> do
773+
PiSort _c a s1 s2 -> do
774774
-- We ignore occurrences in the blocked dependency check (these will
775775
-- vanish after 'PiSort' reduces)
776776
metaOccurs m a

‎src/full/Agda/TypeChecking/Monad/Context.hs‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,11 +801,21 @@ getVarInfo x =
801801
-- TODO: It would be worthwhile investigating who wants to access
802802
-- an out-of-scope variable.
803803

804-
-- | Create a dummy context large enough for the given thing to be well-scoped
804+
-- | Change to a dummy context large enough for the given thing to be
805+
-- well-scoped
805806
-- (Very hacky, should only be used if there is no alternative)
806807
inLargeEnoughContext :: (ReadTCState m, MonadAddContext m, Free a)
807808
=> a -> m b -> m b
808809
inLargeEnoughContext t c = do
809810
let len = 1 + foldl' max 0 (freeVarList t)
810811
let dummies = replicate len __DUMMY_DOM__
811812
inTopContext $ addContext dummies c
813+
814+
-- | Run the continuation on the old codomain sort, in an appropriate context
815+
codomainSortOldM :: (ReadTCState m, MonadAddContext m) =>
816+
Dom Type -> Sort -> BlockedDepCheck Sort -> (Sort -> m a) -> m a
817+
codomainSortOldM dom s2 CodomainSortSame c = do
818+
addContext dom $ c s2
819+
codomainSortOldM dom s2 (CodomainSortOld s2Old) c = do
820+
inLargeEnoughContext s2Old $ c s2Old
821+

‎src/full/Agda/TypeChecking/Reduce.hs‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -469,19 +469,18 @@ instance Reduce Sort where
469469
Blocked b (c, s1 , s2Abs) -> return $!
470470
blockedOn b $ PiSort c a s1 s2Abs
471471
NotBlocked _ (c, s1 , s2Abs) -> do
472-
let s2Old = codomainSortOld (unAbs s2Abs) c
472+
let dom = El s1 <$> a
473473
-- In theory we should just call piSort' here. However, we also want
474474
-- to reduce the codomain sort to make it non-dependent when
475475
-- possible. So we use forceNonDep and in case we are dealing with a
476476
-- proper Abs we call piSortAbs directly.
477-
let dom = El s1 <$> a
478-
inLargeEnoughContext s2Old (forceNonDepSort s2Old) >>= \case
477+
codomainSortOldM dom (unAbs s2Abs) c forceNonDepSort >>= \case
479478
-- If the codomain sort is non-dependent, we reduce to a FunSort
480479
(NotFree, s2Old) -> do
481480
-- We need to obtain a strengthened version of the codomain sort
482481
s2 <- case c of
483482
CodomainSortSame -> pure s2Old
484-
CodomainSortOld _ ->
483+
CodomainSortOld{} ->
485484
addContext dom (forceNonDepSort $! unAbs s2Abs) >>= \case
486485
(NotFree, s2) -> pure s2
487486
-- If 's2Old' is non dependent, then 's2' must also be
@@ -1668,18 +1667,18 @@ instance InstantiateFull Sort where
16681667
instantiateFull' s = do
16691668
s <- instantiate' s
16701669
case s of
1671-
Univ u n -> Univ u <$!> instantiateFull' n
1670+
Univ u n -> Univ u <$!> instantiateFull' n
16721671
PiSort c a s1 s2 -> uncurry4 piSortM' =<< instantiateFull' (c, a, s1, s2)
1673-
FunSort s1 s2 -> uncurry funSortM =<< instantiateFull' (s1, s2)
1674-
UnivSort s -> univSort <$!> instantiateFull' s
1675-
Inf _ _ -> return s
1676-
SizeUniv -> return s
1677-
LockUniv -> return s
1678-
LevelUniv -> return s
1679-
IntervalUniv -> return s
1680-
MetaS x es -> MetaS x <$!> instantiateFull' es
1681-
DefS d es -> DefS d <$!> instantiateFull' es
1682-
DummyS{} -> return s
1672+
FunSort s1 s2 -> uncurry funSortM =<< instantiateFull' (s1, s2)
1673+
UnivSort s -> univSort <$!> instantiateFull' s
1674+
Inf _ _ -> return s
1675+
SizeUniv -> return s
1676+
LockUniv -> return s
1677+
LevelUniv -> return s
1678+
IntervalUniv -> return s
1679+
MetaS x es -> MetaS x <$!> instantiateFull' es
1680+
DefS d es -> DefS d <$!> instantiateFull' es
1681+
DummyS{} -> return s
16831682

16841683
instance (Free a, InstantiateFull a)
16851684
=> InstantiateFull (BlockedDepCheck a) where

‎src/full/Agda/TypeChecking/Substitute.hs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,7 +988,7 @@ instance Subst a => Subst (Sort' a) where
988988
-- is stable under injective substitutions
989989
then CodomainSortSame
990990
else CodomainSortOld $! unAbs s2
991-
CodomainSortOld _ -> c
991+
CodomainSortOld{} -> c
992992
FunSort s1 s2 -> FunSort (applySubst rho s1) (applySubst rho s2)
993993
UnivSort s -> UnivSort $ applySubst rho s
994994
MetaS x es -> MetaS x $! subE rho es

0 commit comments

Comments
 (0)