Skip to content

Commit 84e0573

Browse files
committed
Fix definition of ensureTupleType in SCTypeCheck.hs.
With the new tuple representation, a single tuple type is represented as not a single AST node, but a whole pile of constructor applications (`Tuple`, `TypeCons`, `TypeNil`). A single call to WHNF followed by running the syntactic recognizer is not sufficient; we may need to evaluate to WHNF separately on each constructor.
1 parent 453cdb0 commit 84e0573

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

saw-core/src/Verifier/SAW/SCTypeCheck.hs

+25-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
{-# LANGUAGE MultiParamTypeClasses #-}
66
{-# LANGUAGE TypeFamilies #-}
77
{-# LANGUAGE LambdaCase #-}
8+
{-# LANGUAGE OverloadedStrings #-}
89

910
{- |
1011
Module : Verifier.SAW.SCTypeCheck
@@ -573,10 +574,31 @@ ensureRecognizer f err trm =
573574
ensureSort :: Term -> TCM Sort
574575
ensureSort tp = ensureRecognizer asSort (NotSort tp) tp
575576

576-
-- | Ensure a 'Term' is a tuple type, normalizing if necessary, and return the
577-
-- components of that tuple type
577+
-- | Ensure a 'Term' is a @TypeList@, normalizing if necessary, and
578+
-- return the components of that @TypeList@. Note that this function
579+
-- cannot be correctly implemented with 'ensureRecognizer', because
580+
-- that function does not normalize deeply enough.
581+
ensureTypeList :: Term -> TCM (Maybe [Term])
582+
ensureTypeList t =
583+
do t' <- typeCheckWHNF t
584+
case asCtor t' of
585+
Just (c, [])
586+
| primName c == "Prelude.TypeNil" -> pure (Just [])
587+
Just (c, [t1, t2])
588+
| primName c == "Prelude.TypeCons" ->
589+
do ts <- ensureTypeList t2
590+
pure ((t1 :) <$> ts)
591+
_ -> pure Nothing
592+
593+
-- | Ensure a 'Term' is a tuple type, normalizing if necessary, and
594+
-- return the components of that tuple type. Note that this function
595+
-- cannot be correctly implemented with 'ensureRecognizer', because
596+
-- that function does not normalize deeply enough.
578597
ensureTupleType :: Term -> TCM [Term]
579-
ensureTupleType tp = ensureRecognizer asTupleType (NotSort tp) tp
598+
ensureTupleType tp =
599+
do let err = NotTupleType tp
600+
t <- ensureRecognizer (isGlobalDef "Prelude.Tuple" @> Just) err tp
601+
maybe (throwTCError err) pure =<< ensureTypeList t
580602

581603
-- | Ensure a 'Term' is a record type, normalizing if necessary, and return the
582604
-- components of that record type

0 commit comments

Comments
 (0)