RE: [commit: ghc] wip/T14068: Avoid name capture in setJoinResTy (6a50466)
Joachim Aha! I think my comment on Phab is redundant. You are simply avoiding name capture, which is obviously right; you are not restricting the applicability of the transformation. Needless to say, a Note would help in due course. S | -----Original Message----- | From: ghc-commits [mailto:ghc-commits-bounces@haskell.org] On Behalf | Of git@git.haskell.org | Sent: 02 August 2017 04:07 | To: ghc-commits@haskell.org | Subject: [commit: ghc] wip/T14068: Avoid name capture in setJoinResTy | (6a50466) | | Repository : ssh://git@git.haskell.org/ghc | | On branch : wip/T14068 | Link : | https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fghc.ha | skell.org%2Ftrac%2Fghc%2Fchangeset%2F6a5046684f93f1870663119b447fff6ba | eb7a7c4%2Fghc&data=04%7C01%7Csimonpj%40microsoft.com%7Cc45ce3f4deea476 | 9222b08d4d953af74%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6363724 | 00832017356%7CUnknown%7CVW5rbm93bnx7IlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMi | IsIkFOIjoiT3RoZXIifQ%3D%3D%7C- | 1&sdata=29Iajm6oTE3Zm%2Bdl5ocMav7MPw%2FniO9%2BVeuQm38qWXQ%3D&reserved= | 0 | | >--------------------------------------------------------------- | | commit 6a5046684f93f1870663119b447fff6baeb7a7c4 | Author: Joachim Breitner <mail@joachim-breitner.de> | Date: Tue Aug 1 22:48:26 2017 -0400 | | Avoid name capture in setJoinResTy | | | >--------------------------------------------------------------- | | 6a5046684f93f1870663119b447fff6baeb7a7c4 | compiler/types/Type.hs | 22 ++++++++++++++++------ | 1 file changed, 16 insertions(+), 6 deletions(-) | | diff --git a/compiler/types/Type.hs b/compiler/types/Type.hs index | 50a35b0..c69d4ff 100644 | --- a/compiler/types/Type.hs | +++ b/compiler/types/Type.hs | @@ -2445,11 +2445,21 @@ setJoinResTy :: Int -- Number of binders to | skip | -> Type -- New type | -- INVARIANT: If any of the first n binders are foralls, those tyvars | cannot | -- appear in the original result type. See isValidJoinPointType. | +-- | +-- When we set the return type under a forall, avoid capture! | setJoinResTy orig_ar new_res_ty orig_ty | - = go orig_ar orig_ty | + = go init_subst orig_ar orig_ty | where | - go 0 _ = new_res_ty | - go n ty | Just (arg_bndr, res_ty) <- splitPiTy_maybe ty | - = mkPiTy arg_bndr (go (n-1) res_ty) | - | otherwise | - = pprPanic "setJoinResTy" (ppr orig_ar <+> ppr orig_ty) | + init_subst :: TCvSubst | + init_subst = mkEmptyTCvSubst (mkInScopeSet (tyCoVarsOfType | + new_res_ty)) | + | + go _ 0 _ = new_res_ty | + go subst n ty | + | Just (t, ty') <- splitForAllTy_maybe ty | + , let (subst', t') = substTyVarBndr subst t | + = mkForAllTy t' Inferred (go subst' (n-1) ty') | + | Just (arg_ty, ty') <- splitFunTy_maybe ty | + , let arg_ty' = substTy subst arg_ty | + = mkFunTy arg_ty' (go subst (n-1) ty') | + | otherwise | + = pprPanic "setJoinResTy" (ppr orig_ar <+> ppr orig_ty) | | _______________________________________________ | ghc-commits mailing list | ghc-commits@haskell.org | https://na01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.h | askell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc- | commits&data=04%7C01%7Csimonpj%40microsoft.com%7Cc45ce3f4deea4769222b0 | 8d4d953af74%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C6363724008320 | 17356%7CUnknown%7CVW5rbm93bnx7IlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFO | IjoiT3RoZXIifQ%3D%3D%7C- | 1&sdata=7%2FAY0EcihvMkjGOHdYdpOog2Roahk0XD%2BunNg54pKFc%3D&reserved=0
participants (1)
-
Simon Peyton Jones