Apoorv Ingle pushed to branch wip/ani/T27156 at Glasgow Haskell Compiler / GHC

Commits:

8 changed files:

Changes:

  • compiler/GHC/Hs/Expr.hs
    ... ... @@ -652,7 +652,7 @@ tupArgsPresent_maybe = traverse tupArgPresent_maybe
    652 652
     *                                                                      *
    
    653 653
     ********************************************************************* -}
    
    654 654
     
    
    655
    -type instance XXExpr GhcPs = DataConCantHappen
    
    655
    +type instance XXExpr GhcPs = XXExprGhcPs
    
    656 656
     type instance XXExpr GhcRn = XXExprGhcRn
    
    657 657
     type instance XXExpr GhcTc = XXExprGhcTc
    
    658 658
     -- XXExprGhcRn: see Note [Rebindable syntax and XXExprGhcRn] below
    
    ... ... @@ -665,6 +665,10 @@ type instance XXExpr GhcTc = XXExprGhcTc
    665 665
     *                                                                      *
    
    666 666
     ********************************************************************* -}
    
    667 667
     
    
    668
    +data XXExprGhcPs
    
    669
    +  = ReSynBinds HsModuleName (HsExpr GhcPs)
    
    670
    +
    
    671
    +
    
    668 672
     -- See Note [Rebindable syntax and XXExprGhcRn]
    
    669 673
     -- See Note [Expanding HsDo with XXExprGhcRn] in `GHC.Tc.Gen.Do`
    
    670 674
     -- See Note [Typechecking by expansion: overview]
    
    ... ... @@ -681,6 +685,7 @@ data XXExprGhcRn
    681 685
                                -- See Note [Non-overloaded record field selectors] and
    
    682 686
                                -- Note [Record selectors in the AST]
    
    683 687
     
    
    688
    +
    
    684 689
     data XXExprGhcTc
    
    685 690
       = WrapExpr        -- Type and evidence application and abstractions
    
    686 691
           HsWrapper (HsExpr GhcTc)
    
    ... ... @@ -1029,9 +1034,12 @@ ppr_expr (HsFunArr _ arr arg res)
    1029 1034
       = sep [ppr_lexpr arg, pprHsModifiedFunArr arr <+> ppr_lexpr res]
    
    1030 1035
     
    
    1031 1036
     ppr_expr (XExpr x) = case ghcPass @p of
    
    1037
    +  GhcPs -> ppr x
    
    1032 1038
       GhcRn -> ppr x
    
    1033 1039
       GhcTc -> ppr x
    
    1034 1040
     
    
    1041
    +instance Outputable XXExprGhcPs where
    
    1042
    +  ppr (ReSynBinds m e) = text "{{" <+> ppr m <+> text "}}" <+> ppr e
    
    1035 1043
     
    
    1036 1044
     ppr_hse :: forall p. (IsPass p) => HsExpansion (GhcPass p) -> SDoc
    
    1037 1045
     ppr_hse hse
    
    ... ... @@ -1088,10 +1096,14 @@ ppr_infix_expr (HsHole x) = Just $ pprInfixOcc $ case (ghcPass @p, x) of
    1088 1096
       (GhcTc, (HoleVar (L _ v), _)) -> v
    
    1089 1097
       _ -> unnamedHoleRdrName -- TODO: this is the HoleError case; this should print the source text instead of "_".
    
    1090 1098
     ppr_infix_expr (XExpr x)            = case ghcPass @p of
    
    1099
    +                                        GhcPs -> ppr_infix_expr_ps x
    
    1091 1100
                                             GhcRn -> ppr_infix_expr_rn x
    
    1092 1101
                                             GhcTc -> ppr_infix_expr_tc x
    
    1093 1102
     ppr_infix_expr _ = Nothing
    
    1094 1103
     
    
    1104
    +ppr_infix_expr_ps :: XXExprGhcPs -> Maybe SDoc
    
    1105
    +ppr_infix_expr_ps (ReSynBinds{}) = Nothing
    
    1106
    +
    
    1095 1107
     ppr_infix_expr_rn :: XXExprGhcRn -> Maybe SDoc
    
    1096 1108
     ppr_infix_expr_rn (ExpandedThingRn (HSE thing _)) = ppr_infix_hs_expansion thing
    
    1097 1109
     ppr_infix_expr_rn (HsRecSelRn f)            = Just (pprInfixOcc f)
    
    ... ... @@ -1182,9 +1194,13 @@ hsExprNeedsParens prec = go
    1182 1194
         go (HsQual{})                     = prec >= funPrec
    
    1183 1195
         go (HsFunArr{})                   = prec >= funPrec
    
    1184 1196
         go (XExpr x) = case ghcPass @p of
    
    1197
    +                     GhcPs -> go_x_ps x
    
    1185 1198
                          GhcTc -> go_x_tc x
    
    1186 1199
                          GhcRn -> go_x_rn x
    
    1187 1200
     
    
    1201
    +    go_x_ps :: XXExprGhcPs -> Bool
    
    1202
    +    go_x_ps (ReSynBinds _ e) = hsExprNeedsParens prec e
    
    1203
    +
    
    1188 1204
         go_x_tc :: XXExprGhcTc -> Bool
    
    1189 1205
         go_x_tc (WrapExpr _ e)                   = hsExprNeedsParens prec e
    
    1190 1206
         go_x_tc (ExpandedThingTc (HSE thing _))  = hsExpandedNeedsParens thing
    

  • compiler/GHC/Hs/Instances.hs
    ... ... @@ -735,6 +735,7 @@ deriving instance Data (HsExpansion GhcTc)
    735 735
     deriving instance Data a => Data (WithUserRdr a)
    
    736 736
     
    
    737 737
     -- -------------------------------
    
    738
    +deriving instance Data XXExprGhcPs
    
    738 739
     deriving instance Data XXExprGhcTc
    
    739 740
     deriving instance Data XXPatGhcTc
    
    740 741
     
    

  • compiler/GHC/Rename/Expr.hs
    ... ... @@ -327,8 +327,8 @@ rnExpr (HsHole h)
    327 327
     
    
    328 328
     -- HsOverLabel: see Note [Handling overloaded and rebindable constructs]
    
    329 329
     rnExpr (HsOverLabel src v)
    
    330
    -  = do { (from_label, fvs) <- lookupSyntaxName fromLabelClassOpName
    
    331
    -       ; let rs_table = Rebindable [(nameOccName fromLabelClassOpName, from_label)]
    
    330
    +  = do { (from_label, fvs) <- lookupSyntaxName fromLabelClassOpOcc
    
    331
    +       ; let rs_table = Rebindable [(fromLabelClassOpOcc, from_label)]
    
    332 332
            ; return (HsOverLabel (src, rs_table) v, fvs)
    
    333 333
            }
    
    334 334
     
    
    ... ... @@ -353,7 +353,7 @@ rnExpr (HsOverLit x lit)
    353 353
                             , fvs ) }
    
    354 354
     
    
    355 355
     rnExpr (HsQualLit x QualLit{..})
    
    356
    - = do { (funName, fvs) <- lookupNameWithQualifier fromStringName ql_mod
    
    356
    + = do { (funName, fvs) <- lookupNameWithQualifier ql_mod fromStringClassOpOcc
    
    357 357
           ; let ql_val' = case ql_val of
    
    358 358
                             HsQualString st s -> HsQualString st s
    
    359 359
           ; return (HsQualLit x (QualLit (L noAnn funName) ql_mod ql_val'), fvs)
    
    ... ... @@ -401,11 +401,11 @@ rnExpr (HsGetField _ e f)
    401 401
      = do { (getField, fv_getField) <- lookupSyntaxName getFieldClassOpOcc
    
    402 402
           ; (e, fv_e) <- rnLExpr e
    
    403 403
           ; let f' = rnDotFieldOcc <$> f
    
    404
    -            rs_table = Rebindable  [(nameOccName getFieldName, getField)]
    
    404
    +            rs_table = Rebindable  [(getFieldClassOpOcc, getField)]
    
    405 405
           ; return (HsGetField rs_table e f', fv_e `plusFN` fv_getField) }
    
    406 406
     
    
    407 407
     rnExpr (HsProjection _ fs)
    
    408
    -  = do { (getFieldName, fv_getField) <- lookupSyntaxName getFieldName
    
    408
    +  = do { (getFieldName, fv_getField) <- lookupSyntaxName getFieldClassOpOcc
    
    409 409
            ; circName <- rnLookupKnownOccName composeIdOcc
    
    410 410
            ; let fs' = NE.map rnDotFieldOcc fs
    
    411 411
                  rs_table = Rebindable  [(nameOccName getFieldName , getFieldName), (rdrNameOcc compose_RDR, circName)]
    
    ... ... @@ -476,7 +476,7 @@ rnExpr (ExplicitList _ exps)
    476 476
               then return  (ExplicitList NoRebindable exps', fvs)
    
    477 477
               else
    
    478 478
         do { (from_list_n_name, fvs') <- lookupSyntaxName fromListNClassOpOcc
    
    479
    -       ; let rs_table = Rebindable  [(nameOccName fromListNClassOpOcc, from_list_n_name)]
    
    479
    +       ; let rs_table = Rebindable  [(fromListNClassOpOcc, from_list_n_name)]
    
    480 480
                  rn_list  = ExplicitList rs_table exps'
    
    481 481
            ; return ( rn_list
    
    482 482
                     , fvs `plusFN` fvs') } }
    
    ... ... @@ -608,6 +608,12 @@ rnExpr (HsFunArr _ mult arg res)
    608 608
           _ -> False
    
    609 609
         oneType = noLocA $ HsVar noExtField $ noLocA $ noUserRdr oneDataConName
    
    610 610
     
    
    611
    +rnExpr (XExpr (ReSynBinds m e'))
    
    612
    +  =  do { traceRn "XExpr ReSynBinds" (text "module:" <+> ppr m)
    
    613
    +        ; rnExpr e' -- for now just return the renamed expression
    
    614
    +          -- TODO: Bring into scope top level environment of the module m
    
    615
    +        }
    
    616
    +
    
    611 617
     {-
    
    612 618
     ************************************************************************
    
    613 619
     *                                                                      *
    

  • compiler/GHC/Tc/Gen/Expand.hs
    ... ... @@ -19,12 +19,11 @@ import {-# SOURCE #-} GHC.Tc.Gen.Splice( getUntypedSpliceBody )
    19 19
     
    
    20 20
     import GHC.Types.Name
    
    21 21
     import GHC.Types.Name.Reader
    
    22
    -import GHC.Types.Id.Make
    
    23
    -import GHC.Types.SrcLoc
    
    22
    +import GHC.Types.SrcLoc ( GenLocated(L), unLoc )
    
    24 23
     import GHC.Types.SourceText ( SourceText(..) )
    
    25 24
     
    
    26
    -import GHC.Builtin.Names
    
    27
    -
    
    25
    +import GHC.Builtin.KnownOccs
    
    26
    +import GHC.Builtin.WiredIn.Ids ( leftSectionName, rightSectionName )
    
    28 27
     import GHC.Rename.Utils
    
    29 28
     
    
    30 29
     import GHC.Utils.Panic
    
    ... ... @@ -34,6 +33,7 @@ import qualified Data.List.NonEmpty as NE ( map, head, (<|) )
    34 33
     import Data.List.NonEmpty ( NonEmpty(..), init, last, tail )
    
    35 34
     
    
    36 35
     import qualified GHC.LanguageExtensions as LangExt
    
    36
    +import GHC.Builtin.KnownKeys (getFieldClassOpOcc)
    
    37 37
     
    
    38 38
     {- Note [Typechecking by expansion: overview]
    
    39 39
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -123,7 +123,7 @@ tcExpand :: HsExpr GhcRn -> TcM (Maybe (HsExpansion GhcRn))
    123 123
     ------------------------------------------
    
    124 124
     -- Overloaded labels
    
    125 125
     tcExpand e@(HsOverLabel (_, Rebindable rs_table) v)
    
    126
    -  | Just fromLabelName <- lookup (nameOccName fromLabelClassOpName) rs_table
    
    126
    +  | Just fromLabelName <- lookup fromLabelClassOpOcc rs_table
    
    127 127
       , let hs_ty_arg = mkEmptyWildCardBndrs $ wrapGenSpan $
    
    128 128
                           HsTyLit noExtField (HsString NoSourceText v)
    
    129 129
       = return $ Just $
    
    ... ... @@ -178,7 +178,7 @@ tcExpand e@(HsIf (Rebindable rs_table) p b1 b2)
    178 178
     -- Record dot syntax
    
    179 179
     
    
    180 180
     tcExpand e@(HsGetField (Rebindable rs_table) expr f)
    
    181
    - | Just getField <- lookup (nameOccName getFieldName) rs_table
    
    181
    + | Just getField <- lookup getFieldClassOpOcc rs_table
    
    182 182
      = return $ Just $
    
    183 183
        HSE { hse_ctxt = ExprCtxt e
    
    184 184
            , hse_exp = wrapGenSpan $ (mkGetField getField expr (fmap (unLoc . dfoLabel) f)) }
    
    ... ... @@ -187,7 +187,7 @@ tcExpand e@(HsGetField (Rebindable rs_table) expr f)
    187 187
                                  , ppr e ])
    
    188 188
     
    
    189 189
     tcExpand e@(HsProjection (Rebindable rs_table) fs)
    
    190
    - | Just getField <- lookup (nameOccName getFieldName) rs_table
    
    190
    + | Just getField <- lookup getFieldClassOpOcc rs_table
    
    191 191
      , Just circ <- lookup (rdrNameOcc compose_RDR) rs_table
    
    192 192
      = return $ Just $
    
    193 193
        HSE { hse_ctxt = ExprCtxt e
    
    ... ... @@ -200,8 +200,8 @@ tcExpand e@(HsProjection (Rebindable rs_table) fs)
    200 200
     tcExpand (RecordUpd NoRebindable _ _ ) = return Nothing -- until #27160 is fixed
    
    201 201
     
    
    202 202
     tcExpand e@(RecordUpd (Rebindable rs_table) (L l expr) (OverloadedRecUpdFields { olRecUpdFields = us}))
    
    203
    - | Just getField <- lookup (nameOccName getFieldName) rs_table
    
    204
    - , Just setField <- lookup (nameOccName setFieldName) rs_table
    
    203
    + | Just getField <- lookup getFieldClassOpOcc rs_table
    
    204
    + , Just setField <- lookup setFieldClassOpOcc rs_table
    
    205 205
      = return $ Just $
    
    206 206
        HSE { hse_ctxt = ExprCtxt e
    
    207 207
            , hse_exp = wrapGenSpan $ mkRecordDotUpd getField setField (L l expr) us }
    
    ... ... @@ -235,7 +235,7 @@ tcExpand e@(SectionL _ expr op)
    235 235
     tcExpand (ExplicitList NoRebindable _ )
    
    236 236
       = return Nothing -- rebindable syntax is off
    
    237 237
     tcExpand e@(ExplicitList (Rebindable rs_table) exps)
    
    238
    -  | Just from_list_n_name <- lookup (nameOccName fromListNName) rs_table
    
    238
    +  | Just from_list_n_name <- lookup fromListNClassOpOcc rs_table
    
    239 239
       = do { loc <- getSrcSpanM -- See Note [Source locations for implicit function calls]
    
    240 240
            ; let lit_n    = mkIntegralLit (length exps)
    
    241 241
                  hs_lit   = genHsIntegralLit lit_n
    

  • compiler/GHC/Tc/Gen/Expr.hs
    ... ... @@ -595,7 +595,7 @@ tcExprNoExpand (HsProc x pat cmd) res_ty
    595 595
     -- and wrap (static e) in a call to
    
    596 596
     --    fromStaticPtr :: IsStatic p => StaticPtr a -> p a
    
    597 597
     
    
    598
    -tcExpr (HsStatic free_names expr) res_ty
    
    598
    +tcExprNoExpand (HsStatic free_names expr) res_ty
    
    599 599
       = do  { res_ty          <- expTypeToType res_ty
    
    600 600
             ; (co, (p_ty, expr_ty)) <- matchExpectedAppTy res_ty
    
    601 601
             ; (expr', lie) <- captureConstraints $
    

  • compiler/GHC/ThToHs.hs
    ... ... @@ -1228,6 +1228,8 @@ cvtl e = wrapLA (cvt e)
    1228 1228
              ; let tele = setTelescopeBndrsNameSpace varName $
    
    1229 1229
                           mkHsForAllVisTele noAnn tvs'
    
    1230 1230
              ; return $ HsForAll noExtField tele body' }
    
    1231
    +    cvt (ReSynBindsE m e) = do { e' <- cvt e
    
    1232
    +                              ; return $ XExpr (ReSynBinds (mk_modtext m) e') }
    
    1231 1233
     
    
    1232 1234
     {- | #16895 Ensure an infix expression's operator is a variable/constructor.
    
    1233 1235
     Consider this example:
    

  • libraries/ghc-boot-th/GHC/Boot/TH/Ppr.hs
    ... ... @@ -56,6 +56,9 @@ instance Ppr a => Ppr [a] where
    56 56
     instance Ppr Name where
    
    57 57
         ppr v = pprName v
    
    58 58
     
    
    59
    +instance Ppr ModName where
    
    60
    +    ppr (ModName s) = text s
    
    61
    +
    
    59 62
     ------------------------------
    
    60 63
     instance Ppr Info where
    
    61 64
         ppr (TyConI d)     = ppr d
    
    ... ... @@ -250,6 +253,7 @@ pprExp i (ForallE tvars body) =
    250 253
       parensIf (i >= funPrec) $ sep [pprForall tvars [], pprExp qualPrec body]
    
    251 254
     pprExp i (ConstrainedE ctx body) =
    
    252 255
       parensIf (i >= funPrec) $ sep [pprCtxWith pprExp ctx, pprExp qualPrec body]
    
    256
    +pprExp i (ReSynBindsE m e) = text "{{" <+> ppr m <+> text "}}" <+> pprExp i e
    
    253 257
     
    
    254 258
     pprFields :: [(Name,Exp)] -> Doc
    
    255 259
     pprFields = sep . punctuate comma . map (\(s,e) -> pprName' Applied s <+> equals <+> ppr e)
    

  • libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs
    ... ... @@ -904,6 +904,8 @@ data Exp
    904 904
       | ForallE [TyVarBndr Specificity] Exp -- ^ @forall \<vars\>. \<expr\>@
    
    905 905
       | ForallVisE [TyVarBndr ()] Exp      -- ^ @forall \<vars\> -> \<expr\>@
    
    906 906
       | ConstrainedE [Exp] Exp             -- ^ @\<ctxt\> => \<expr\>@
    
    907
    +  | ReSynBindsE ModName Exp            -- Remember to use bindings from the specified modname
    
    908
    +                                       -- while typechecking a typed splice for rebindable syntax
    
    907 909
       deriving( Show, Eq, Ord, Generic )
    
    908 910
     
    
    909 911
     -- | A (field name, expression) pair. See 'RecConE' and 'RecUpdE'.