| ... |
... |
@@ -424,68 +424,43 @@ tcApp rn_expr exp_res_ty |
|
424
|
424
|
; do_ql <- wantQuickLook rn_fun
|
|
425
|
425
|
; (inst_args, app_res_rho) <- tcInstFun do_ql inst_final tc_head fun_sigma rn_args
|
|
426
|
426
|
|
|
427
|
|
- ; case do_ql of
|
|
428
|
|
- NoQL -> do { traceTc "tcApp:NoQL" (ppr rn_fun $$ ppr app_res_rho)
|
|
429
|
|
-
|
|
430
|
|
- -- Step 4.1: subsumption check against expected result type
|
|
431
|
|
- -- See Note [Unify with expected type before typechecking arguments]
|
|
432
|
|
- ; res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
433
|
|
- app_res_rho exp_res_ty
|
|
434
|
|
-
|
|
435
|
|
- -- Step 4.2: typecheck the arguments
|
|
436
|
|
- ; tc_args <- tcValArgs NoQL inst_args
|
|
437
|
|
-
|
|
438
|
|
- -- Step 4.3: wrap up
|
|
439
|
|
- ; finishApp tc_head tc_args app_res_rho res_wrap }
|
|
440
|
|
-
|
|
441
|
|
- DoQL -> do { traceTc "tcApp:DoQL" (ppr rn_fun $$ ppr app_res_rho)
|
|
442
|
|
-
|
|
443
|
|
- -- Step 5.1: Take a quick look at the result type
|
|
|
427
|
+ ; app_res_rho <- case do_ql of
|
|
|
428
|
+ NoQL -> return app_res_rho
|
|
|
429
|
+ DoQL -> do { -- Step 5.1: Take a quick look at the result type
|
|
444
|
430
|
-- See Note [QuickLook: arguments before result]
|
|
445
|
|
- ; case exp_res_ty of
|
|
446
|
|
- Check exp_rho -> quickLookResultType app_res_rho exp_rho
|
|
447
|
|
- Infer {} -> return ()
|
|
|
431
|
+ case exp_res_ty of
|
|
|
432
|
+ Check exp_rho -> quickLookResultType app_res_rho exp_rho
|
|
|
433
|
+ Infer {} -> return ()
|
|
448
|
434
|
|
|
449
|
435
|
-- Step 5.3: zonk to expose the polymorphism hidden under
|
|
450
|
436
|
-- QuickLook instantiation variables in `app_res_rho`
|
|
451
|
|
- ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
|
|
|
437
|
+ -- from either quickLookArg or quickLookResultType
|
|
|
438
|
+ ; liftZonkM $ zonkTcType app_res_rho }
|
|
452
|
439
|
|
|
453
|
|
- -- Step 5.4: subsumption check against the expected type
|
|
454
|
|
- -- See Note [Unify with expected type before typechecking arguments]
|
|
455
|
|
- ; res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
456
|
|
- app_res_rho exp_res_ty
|
|
457
|
|
-
|
|
458
|
|
- -- Step 5.2: typecheck the arguments, and monomorphise
|
|
459
|
|
- -- any un-unified instantiation variables
|
|
460
|
|
- ; tc_args <- tcValArgs DoQL inst_args
|
|
461
|
|
-
|
|
462
|
|
- -- Step 5.5: wrap up
|
|
463
|
|
- ; finishApp tc_head tc_args app_res_rho res_wrap } }
|
|
464
|
|
-
|
|
465
|
|
--- | Variant of 'getDeepSubsumptionFlag' which enables a top-level subsumption
|
|
466
|
|
--- in order to implement the plan of Note [Typechecking data constructors].
|
|
467
|
|
-getDeepSubsumptionFlag_DataConHead :: HsExpr GhcTc -> TcM DeepSubsumptionFlag
|
|
468
|
|
-getDeepSubsumptionFlag_DataConHead app_head =
|
|
469
|
|
- do { user_ds <- xoptM LangExt.DeepSubsumption
|
|
470
|
|
- ; return $
|
|
471
|
|
- if | user_ds
|
|
472
|
|
- -> Deep DeepSub
|
|
473
|
|
- | XExpr (ConLikeTc (RealDataCon {})) <- app_head
|
|
474
|
|
- -> Deep TopSub
|
|
475
|
|
- | otherwise
|
|
476
|
|
- -> Shallow
|
|
477
|
|
- }
|
|
|
440
|
+ ; finishApp do_ql rn_expr tc_head inst_args app_res_rho exp_res_ty }
|
|
478
|
441
|
|
|
479
|
|
-finishApp :: (HsExpr GhcTc, AppCtxt) -> [HsExprArg 'TcpTc]
|
|
480
|
|
- -> TcRhoType -> HsWrapper
|
|
|
442
|
+finishApp :: QLFlag -> HsExpr GhcRn
|
|
|
443
|
+ -> (HsExpr GhcTc, AppCtxt) -> [HsExprArg 'TcpInst]
|
|
|
444
|
+ -> TcRhoType -> ExpRhoType
|
|
481
|
445
|
-> TcM (HsExpr GhcTc)
|
|
482
|
446
|
-- Do final checks and wrap up the result
|
|
483
|
|
-finishApp tc_head@(tc_fun,_) tc_args app_res_rho res_wrap
|
|
484
|
|
- = do {
|
|
485
|
|
- -- Reconstruct, with a horrible special case for tagToEnum#.
|
|
486
|
|
- res_expr <- if isTagToEnum tc_fun
|
|
|
447
|
+-- Precondition: app_res_rho has no polymorphism hidden under instantiation variables
|
|
|
448
|
+finishApp do_ql rn_expr tc_head@(tc_fun,_) inst_args
|
|
|
449
|
+ app_res_rho exp_res_ty
|
|
|
450
|
+ = do { -- Step 5.4: subsumption check against the expected type
|
|
|
451
|
+ -- See Note [Unify with expected type before typechecking arguments]
|
|
|
452
|
+ res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
|
453
|
+ app_res_rho exp_res_ty
|
|
|
454
|
+
|
|
|
455
|
+ -- Step 5.2: Typecheck the arguments, and monomorphise
|
|
|
456
|
+ -- any un-unified instantiation variables
|
|
|
457
|
+ ; tc_args <- tcValArgs do_ql inst_args
|
|
|
458
|
+
|
|
|
459
|
+ -- Horrible special case for tagToEnum#.
|
|
|
460
|
+ ; res_expr <- if isTagToEnum tc_fun
|
|
487
|
461
|
then tcTagToEnum tc_head tc_args app_res_rho
|
|
488
|
462
|
else return (rebuildHsApps tc_head tc_args)
|
|
|
463
|
+
|
|
489
|
464
|
; traceTc "End tcApp }" (ppr tc_fun)
|
|
490
|
465
|
; return (mkHsWrap res_wrap res_expr) }
|
|
491
|
466
|
|
| ... |
... |
@@ -630,10 +605,8 @@ tcValArg _ (EValArgQL { eaql_wanted = wanted |
|
630
|
605
|
quickLookResultType app_res_rho exp_arg_rho -- the qlUnify
|
|
631
|
606
|
|
|
632
|
607
|
; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
|
|
633
|
|
- ; res_wrap <- checkResultTy rn_expr tc_head inst_args
|
|
634
|
|
- app_res_rho (mkCheckExpType exp_arg_rho)
|
|
635
|
|
- ; tc_args <- tcValArgs DoQL inst_args
|
|
636
|
|
- ; finishApp tc_head tc_args app_res_rho res_wrap }
|
|
|
608
|
+ ; finishApp DoQL rn_expr tc_head inst_args app_res_rho
|
|
|
609
|
+ (mkCheckExpType exp_arg_rho) }
|
|
637
|
610
|
|
|
638
|
611
|
; traceTc "tcEValArgQL }" $
|
|
639
|
612
|
vcat [ text "app_res_rho:" <+> ppr app_res_rho ]
|
| ... |
... |
@@ -644,6 +617,20 @@ tcValArg _ (EValArgQL { eaql_wanted = wanted |
|
644
|
617
|
|
|
645
|
618
|
|
|
646
|
619
|
--------------------
|
|
|
620
|
+-- | Variant of 'getDeepSubsumptionFlag' which enables a top-level subsumption
|
|
|
621
|
+-- in order to implement the plan of Note [Typechecking data constructors].
|
|
|
622
|
+getDeepSubsumptionFlag_DataConHead :: HsExpr GhcTc -> TcM DeepSubsumptionFlag
|
|
|
623
|
+getDeepSubsumptionFlag_DataConHead app_head =
|
|
|
624
|
+ do { user_ds <- xoptM LangExt.DeepSubsumption
|
|
|
625
|
+ ; return $
|
|
|
626
|
+ if | user_ds
|
|
|
627
|
+ -> Deep DeepSub
|
|
|
628
|
+ | XExpr (ConLikeTc (RealDataCon {})) <- app_head
|
|
|
629
|
+ -> Deep TopSub
|
|
|
630
|
+ | otherwise
|
|
|
631
|
+ -> Shallow
|
|
|
632
|
+ }
|
|
|
633
|
+
|
|
647
|
634
|
whenQL :: QLFlag -> ZonkM () -> TcM ()
|
|
648
|
635
|
whenQL DoQL thing_inside = liftZonkM thing_inside
|
|
649
|
636
|
whenQL NoQL _ = return ()
|