@@ -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
491508codomainSortOld :: 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
18541871instance Pretty t => Pretty (BlockedDepCheck t ) where
18551872 pretty (CodomainSortOld s) = " CodomainSortOld" <+> pretty s
1856- pretty CodomainSortSame = " CodomainSortSame"
1873+ pretty CodomainSortSame = " CodomainSortSame"
18571874
18581875instance (Pretty t , Pretty e ) => Pretty (Dom' t e ) where
18591876 pretty dom = pLock <+> pTac <+> pDom dom (pretty (getModality dom) <+> pretty (unDom dom))
0 commit comments