Skip to content

Commit 1a80b0d

Browse files
Move hole detection from synthesis to checking
1 parent 45456af commit 1a80b0d

File tree

1 file changed

+46
-13
lines changed
  • liquidhaskell-boot/src/Language/Haskell/Liquid/Constraint

1 file changed

+46
-13
lines changed

liquidhaskell-boot/src/Language/Haskell/Liquid/Constraint/Generate.hs

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -387,9 +387,17 @@ cconsE' γ e@(Cast e' c) t
387387
addC (SubC γ (F.notracepp ("Casted Type for " ++ GM.showPpr e ++ "\n init type " ++ showpp t) t') t) ("cconsE Cast: " ++ GM.showPpr e)
388388

389389
cconsE' γ e t
390-
= do te <- consE γ e
390+
= do
391+
_ <- when (warnOnTermHoles (getConfig γ)) maybeAddHole
392+
te <- consE γ e
391393
te' <- instantiatePreds γ e te >>= addPost γ
392394
addC (SubC γ te' t) ("cconsE: " ++ "\n t = " ++ showpp t ++ "\n te = " ++ showpp te ++ GM.showPpr e)
395+
where
396+
maybeAddHole = do
397+
isItHole <- detectTypedHole γ e
398+
case isItHole of
399+
Just (srcSpan, x) -> addHole (RealSrcSpan srcSpan Strict.Nothing) x t γ
400+
_ -> return ()
393401

394402
lambdaSingleton :: CGEnv -> F.TCEmb TyCon -> Var -> CoreExpr -> CG (UReft F.Reft)
395403
lambdaSingleton γ tce x e
@@ -512,18 +520,43 @@ consE γ (Var x)
512520
consE _ (Lit c)
513521
= refreshVV $ uRType $ literalFRefType c
514522

515-
consE γ e'@(App _ _) =
516-
do
517-
t <- if (warnOnTermHoles (getConfig γ)) then synthesizeWithHole else consEApp γ e'
518-
return t
519-
where
520-
synthesizeWithHole = do
521-
isItHole <- detectTypedHole γ e'
522-
t <- consEApp γ e'
523-
_ <- case isItHole of
524-
Just (srcSpan, x) -> addHole (RealSrcSpan srcSpan Strict.Nothing) x t γ
525-
_ -> return ()
526-
return t
523+
consE γ e'@(App e a@(Type τ))
524+
= do RAllT α te _ <- checkAll ("Non-all TyApp with expr", e) γ <$> consE γ e
525+
t <- if not (nopolyinfer (getConfig γ)) && isPos α && isGenericVar (ty_var_value α) te
526+
then freshTyType (typeclass (getConfig γ)) TypeInstE e τ
527+
else trueTy (typeclass (getConfig γ)) τ
528+
addW $ WfC γ t
529+
t' <- refreshVV t
530+
tt0 <- instantiatePreds γ e' (subsTyVarMeet' (ty_var_value α, t') te)
531+
let tt = makeSingleton γ (simplify e') $ subsTyReft γ (ty_var_value α) τ tt0
532+
return $ case rTVarToBind α of
533+
Just (x, _) -> maybe (checkUnbound γ e' x tt a) (F.subst1 tt . (x,)) (argType τ)
534+
Nothing -> tt
535+
where
536+
isPos α = not (extensionality (getConfig γ)) || rtv_is_pol (ty_var_info α)
537+
538+
consE γ e'@(App e a) | Just aDict <- getExprDict γ a
539+
= case dhasinfo (dlookup (denv γ) aDict) (getExprFun γ e) of
540+
Just riSig -> return $ fromRISig riSig
541+
_ -> do
542+
([], πs, te) <- bkUniv <$> consE γ e
543+
te' <- instantiatePreds γ e' $ foldr RAllP te πs
544+
(γ', te''') <- dropExists γ te'
545+
te'' <- dropConstraints γ te'''
546+
updateLocA {- πs -} (exprLoc e) te''
547+
let RFun x _ tx t _ = checkFun ("Non-fun App with caller ", e') γ te''
548+
cconsE γ' a tx
549+
addPost γ' $ maybe (checkUnbound γ' e' x t a) (F.subst1 t . (x,)) (argExpr γ a)
550+
551+
consE γ e'@(App e a)
552+
= do ([], πs, te) <- bkUniv <$> consE γ {- GM.tracePpr ("APP-EXPR: " ++ GM.showPpr (exprType e)) -} e
553+
te1 <- instantiatePreds γ e' $ foldr RAllP te πs
554+
(γ', te2) <- dropExists γ te1
555+
te3 <- dropConstraints γ te2
556+
updateLocA (exprLoc e) te3
557+
let RFun x _ tx t _ = checkFun ("Non-fun App with caller ", e') γ te3
558+
cconsE γ' a tx
559+
makeSingleton γ' (simplify e') <$> addPost γ' (maybe (checkUnbound γ' e' x t a) (F.subst1 t . (x,)) (argExpr γ $ simplify a))
527560

528561
consE γ (Lam α e) | isTyVar α
529562
= do γ' <- updateEnvironment γ α

0 commit comments

Comments
 (0)