recursion-ninja pushed to branch wip/fix-26700 at Glasgow Haskell Compiler / GHC
Commits:
-
73251e50
by Recursion Ninja at 2026-02-06T16:07:21-05:00
-
9ddbfca5
by Recursion Ninja at 2026-02-06T16:50:48-05:00
27 changed files:
- compiler/GHC/CoreToStg.hs
- compiler/GHC/Hs/Instances.hs
- compiler/GHC/HsToCore/Errors/Types.hs
- compiler/GHC/HsToCore/Foreign/C.hs
- compiler/GHC/HsToCore/Foreign/Call.hs
- compiler/GHC/HsToCore/Foreign/Decl.hs
- compiler/GHC/HsToCore/Foreign/JavaScript.hs
- compiler/GHC/HsToCore/Foreign/Wasm.hs
- compiler/GHC/Rename/Module.hs
- compiler/GHC/StgToByteCode.hs
- compiler/GHC/StgToCmm/Foreign.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Foreign.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Types/ErrCtxt.hs
- compiler/GHC/Types/ForeignCall.hs
- compiler/Language/Haskell/Syntax/Decls.hs
- compiler/Language/Haskell/Syntax/Decls/Foreign.hs
- compiler/Language/Haskell/Syntax/Extension.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Hoogle.hs
- utils/haddock/haddock-api/src/Haddock/Backends/LaTeX.hs
- utils/haddock/haddock-api/src/Haddock/Backends/Xhtml/DocMarkup.hs
- utils/haddock/haddock-api/src/Haddock/Interface/LexParseRn.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs
- utils/haddock/haddock-api/src/Haddock/InterfaceFile.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
Changes:
| ... | ... | @@ -554,10 +554,11 @@ mkStgApp f how_bound core_args stg_args res_ty |
| 554 | 554 | StgOpApp (StgPrimOp op) stg_args res_ty
|
| 555 | 555 | |
| 556 | 556 | -- A call to some primitive Cmm function.
|
| 557 | - FCallId (CCall (CCallSpec (StaticTarget ext lbl ForeignFunction)
|
|
| 558 | - PrimCallConv _))
|
|
| 557 | + FCallId (CCall (CCallSpec
|
|
| 558 | + (StaticTarget ext lbl ForeignFunction) PrimCallConv _))
|
|
| 559 | + | TargetIsInThat unit <- staticTargetUnit ext
|
|
| 559 | 560 | -> assert exactly_saturated $
|
| 560 | - StgOpApp (StgPrimCallOp (PrimCall lbl (staticTargetUnit ext))) stg_args res_ty
|
|
| 561 | + StgOpApp (StgPrimCallOp (PrimCall lbl unit)) stg_args res_ty
|
|
| 561 | 562 | |
| 562 | 563 | -- A regular foreign call.
|
| 563 | 564 | FCallId call -> assert exactly_saturated $
|
| ... | ... | @@ -33,7 +33,6 @@ import GHC.Types.Name.Reader (WithUserRdr(..)) |
| 33 | 33 | import GHC.Types.InlinePragma (ActivationGhc)
|
| 34 | 34 | import GHC.Data.BooleanFormula (BooleanFormula(..))
|
| 35 | 35 | import Language.Haskell.Syntax.Decls
|
| 36 | -import Language.Haskell.Syntax.Decls.Foreign
|
|
| 37 | 36 | import Language.Haskell.Syntax.Decls.Overlap (OverlapMode(..))
|
| 38 | 37 | import Language.Haskell.Syntax.Extension (Anno)
|
| 39 | 38 | import Language.Haskell.Syntax.Binds.InlinePragma (ActivationX(..), InlinePragma(..))
|
| ... | ... | @@ -250,16 +249,21 @@ deriving instance Data (CImportSpec GhcPs) |
| 250 | 249 | deriving instance Data (CImportSpec GhcRn)
|
| 251 | 250 | deriving instance Data (CImportSpec GhcTc)
|
| 252 | 251 | |
| 253 | --- deriving instance (DataIdLR p p) => Data (CImportSpec p)
|
|
| 252 | +-- deriving instance (DataIdLR p p) => Data (CCallTarget p)
|
|
| 254 | 253 | deriving instance Data (CCallTarget GhcPs)
|
| 255 | 254 | deriving instance Data (CCallTarget GhcRn)
|
| 256 | 255 | deriving instance Data (CCallTarget GhcTc)
|
| 257 | 256 | |
| 258 | --- deriving instance (DataIdLR p p) => Data (CImportSpec p)
|
|
| 257 | +-- deriving instance (DataIdLR p p) => Data (CType p)
|
|
| 259 | 258 | deriving instance Data (CType GhcPs)
|
| 260 | 259 | deriving instance Data (CType GhcRn)
|
| 261 | 260 | deriving instance Data (CType GhcTc)
|
| 262 | 261 | |
| 262 | +-- deriving instance (DataIdLR p p) => Data (Header p)
|
|
| 263 | +deriving instance Data (Header GhcPs)
|
|
| 264 | +deriving instance Data (Header GhcRn)
|
|
| 265 | +deriving instance Data (Header GhcTc)
|
|
| 266 | + |
|
| 263 | 267 | -- deriving instance (DataIdLR p p) => Data (RuleDecls p)
|
| 264 | 268 | deriving instance Data (RuleDecls GhcPs)
|
| 265 | 269 | deriving instance Data (RuleDecls GhcRn)
|
| ... | ... | @@ -13,7 +13,6 @@ import GHC.Driver.Flags (WarningFlag) |
| 13 | 13 | import GHC.Hs
|
| 14 | 14 | import GHC.HsToCore.Pmc.Solver.Types
|
| 15 | 15 | import GHC.Types.Error
|
| 16 | -import GHC.Types.ForeignCall (CLabelString)
|
|
| 17 | 16 | import GHC.Types.Id
|
| 18 | 17 | import GHC.Types.InlinePragma (ActivationGhc)
|
| 19 | 18 | import GHC.Types.Name (Name)
|
| ... | ... | @@ -68,29 +68,28 @@ dsCFExport:: Id -- Either the exported Id, |
| 68 | 68 | -- from C, and its representation type
|
| 69 | 69 | -> CLabelString -- The name to export to C land
|
| 70 | 70 | -> CCallConv
|
| 71 | - -> ForeignKind -- If it is a function,
|
|
| 72 | - -- then is foreign export dynamic
|
|
| 73 | - -- so invoke IO action that's hanging off
|
|
| 74 | - -- the first argument's stable pointer
|
|
| 71 | + -> ExportLinking -- If foreign export is dynamic
|
|
| 72 | + -- then invoke IO action that's hanging off
|
|
| 73 | + -- the first argument's stable pointer
|
|
| 75 | 74 | -> DsM ( CHeader -- contents of Module_stub.h
|
| 76 | 75 | , CStub -- contents of Module_stub.c
|
| 77 | 76 | , String -- string describing type to pass to createAdj.
|
| 78 | 77 | )
|
| 79 | 78 | |
| 80 | -dsCFExport fn_id co ext_name cconv target_kind = do
|
|
| 79 | +dsCFExport fn_id co ext_name cconv isDyn = do
|
|
| 81 | 80 | let
|
| 82 | 81 | ty = coercionRKind co
|
| 83 | 82 | (bndrs, orig_res_ty) = tcSplitPiTys ty
|
| 84 | 83 | fe_arg_tys' = mapMaybe anonPiTyBinderType_maybe bndrs
|
| 85 | 84 | -- We must use tcSplits here, because we want to see
|
| 86 | 85 | -- the (IO t) in the corner of the type!
|
| 87 | - fe_arg_tys = case target_kind of
|
|
| 88 | - ForeignFunction -> tail fe_arg_tys'
|
|
| 89 | - _ -> fe_arg_tys'
|
|
| 86 | + (fe_arg_tys, m_fn_id) = case isDyn of
|
|
| 87 | + ExportIsDynamic -> (tail fe_arg_tys', Nothing)
|
|
| 88 | + ExportIsStatic -> (fe_arg_tys', Just fn_id)
|
|
| 90 | 89 | |
| 91 | 90 | -- Look at the result type of the exported function, orig_res_ty
|
| 92 | - -- If it's IO t, return (t, ForeignFunction)
|
|
| 93 | - -- If it's plain t, return (t, ForeignValue)
|
|
| 91 | + -- If it's IO t, return (t, True)
|
|
| 92 | + -- If it's plain t, return (t, False)
|
|
| 94 | 93 | (res_ty, is_IO_res_ty) = case tcSplitIOType_maybe orig_res_ty of
|
| 95 | 94 | -- The function already returns IO t
|
| 96 | 95 | Just (_ioTyCon, res_ty) -> (res_ty, True)
|
| ... | ... | @@ -99,16 +98,14 @@ dsCFExport fn_id co ext_name cconv target_kind = do |
| 99 | 98 | |
| 100 | 99 | dflags <- getDynFlags
|
| 101 | 100 | return $
|
| 102 | - mkFExportCBits dflags ext_name
|
|
| 103 | - (if isDyn then Nothing else Just fn_id)
|
|
| 104 | - fe_arg_tys res_ty is_IO_res_ty cconv
|
|
| 101 | + mkFExportCBits dflags ext_name m_fn_id fe_arg_tys res_ty is_IO_res_ty cconv
|
|
| 105 | 102 | |
| 106 | 103 | dsCImport :: Id
|
| 107 | 104 | -> Coercion
|
| 108 | 105 | -> CImportSpec GhcTc
|
| 109 | 106 | -> CCallConv
|
| 110 | 107 | -> Safety
|
| 111 | - -> Maybe Header
|
|
| 108 | + -> Maybe (Header GhcTc)
|
|
| 112 | 109 | -> DsM ([Binding], CHeader, CStub)
|
| 113 | 110 | dsCImport id co (CLabel cid) _ _ _ = do
|
| 114 | 111 | let ty = coercionLKind co
|
| ... | ... | @@ -186,7 +183,7 @@ dsCFExportDynamic id co0 cconv = do |
| 186 | 183 | export_ty = mkVisFunTyMany stable_ptr_ty arg_ty
|
| 187 | 184 | bindIOId <- dsLookupGlobalId bindIOName
|
| 188 | 185 | stbl_value <- newSysLocalMDs stable_ptr_ty
|
| 189 | - (h_code, c_code, typestring) <- dsCFExport id (mkRepReflCo export_ty) fe_nm cconv True
|
|
| 186 | + (h_code, c_code, typestring) <- dsCFExport id (mkRepReflCo export_ty) fe_nm cconv ExportIsDynamic
|
|
| 190 | 187 | let
|
| 191 | 188 | {-
|
| 192 | 189 | The arguments to the external function which will
|
| ... | ... | @@ -203,7 +200,7 @@ dsCFExportDynamic id co0 cconv = do |
| 203 | 200 | -- (probably in the RTS.)
|
| 204 | 201 | adjustor = fsLit "createAdjustor"
|
| 205 | 202 | |
| 206 | - ccall_adj <- dsCCall adjustor (moduleUnit mod) adj_args PlayRisky (mkTyConApp io_tc [res_ty])
|
|
| 203 | + ccall_adj <- dsCCall adjustor adj_args PlayRisky (mkTyConApp io_tc [res_ty])
|
|
| 207 | 204 | -- PlayRisky: the adjustor doesn't allocate in the Haskell heap or do a callback
|
| 208 | 205 | |
| 209 | 206 | let io_app = mkLams tvs $
|
| ... | ... | @@ -231,7 +228,7 @@ dsCFExportDynamic id co0 cconv = do |
| 231 | 228 | |
| 232 | 229 | |
| 233 | 230 | -- | Foreign calls
|
| 234 | -dsFCall :: Id -> Coercion -> ForeignCall -> Maybe Header
|
|
| 231 | +dsFCall :: Id -> Coercion -> ForeignCall -> Maybe (Header GhcTc)
|
|
| 235 | 232 | -> DsM ([(Id, Expr TyVar)], CHeader, CStub)
|
| 236 | 233 | dsFCall fn_id co fcall mDeclHeader = do
|
| 237 | 234 | let
|
| ... | ... | @@ -331,7 +328,7 @@ dsFCall fn_id co fcall mDeclHeader = do |
| 331 | 328 | toCName :: Id -> String
|
| 332 | 329 | toCName i = showSDocOneLine defaultSDocContext (pprCode (ppr (idName i)))
|
| 333 | 330 | |
| 334 | -toCType :: Type -> (Maybe Header, SDoc)
|
|
| 331 | +toCType :: Type -> (Maybe (Header GhcTc), SDoc)
|
|
| 335 | 332 | toCType = f False
|
| 336 | 333 | where f voidOK t
|
| 337 | 334 | -- First, if we have (Ptr t) of (FunPtr t), then we need to
|
| ... | ... | @@ -382,7 +379,7 @@ mkFExportCBits :: DynFlags |
| 382 | 379 | -> Maybe Id -- Just==static, Nothing==dynamic
|
| 383 | 380 | -> [Type]
|
| 384 | 381 | -> Type
|
| 385 | - -> ForeignKind -- Function <=> returns an IO type
|
|
| 382 | + -> Bool -- True <=> returns an IO type
|
|
| 386 | 383 | -> CCallConv
|
| 387 | 384 | -> (CHeader,
|
| 388 | 385 | CStub,
|
| ... | ... | @@ -519,7 +516,7 @@ mkFExportCBits dflags c_nm maybe_target arg_htys res_hty io_res_ty cc |
| 519 | 516 | char '&' <> cap <>
|
| 520 | 517 | text "rts_apply" <> parens (
|
| 521 | 518 | cap
|
| 522 | - <> (if io_res_ty == ForeignFunction
|
|
| 519 | + <> (if io_res_ty
|
|
| 523 | 520 | then text "ghc_hs_iface->runIO_closure"
|
| 524 | 521 | else text "ghc_hs_iface->runNonIO_closure")
|
| 525 | 522 | <> comma
|
| ... | ... | @@ -42,7 +42,6 @@ import GHC.Types.Literal |
| 42 | 42 | import GHC.Types.RepType (typePrimRep1)
|
| 43 | 43 | |
| 44 | 44 | import GHC.Tc.Utils.TcType
|
| 45 | -import GHC.Unit (Unit)
|
|
| 46 | 45 | |
| 47 | 46 | import GHC.Builtin.Types.Prim
|
| 48 | 47 | import GHC.Builtin.Types
|
| ... | ... | @@ -93,20 +92,19 @@ follows: |
| 93 | 92 | -}
|
| 94 | 93 | |
| 95 | 94 | dsCCall :: CLabelString -- C routine to invoke
|
| 96 | - -> Unit -- Module unit of the C routine
|
|
| 97 | 95 | -> [CoreExpr] -- Arguments (desugared)
|
| 98 | 96 | -- Precondition: none have representation-polymorphic types
|
| 99 | 97 | -> Safety -- Safety of the call
|
| 100 | 98 | -> Type -- Type of the result: IO t
|
| 101 | 99 | -> DsM CoreExpr -- Result, of type ???
|
| 102 | 100 | |
| 103 | -dsCCall lbl unit args may_gc result_ty
|
|
| 101 | +dsCCall lbl args may_gc result_ty
|
|
| 104 | 102 | = do (unboxed_args, arg_wrappers) <- mapAndUnzipM unboxArg args
|
| 105 | 103 | (ccall_result_ty, res_wrapper) <- boxResult result_ty
|
| 106 | 104 | uniq <- newUnique
|
| 107 | 105 | let stExt = StaticTargetGhc
|
| 108 | 106 | { staticTargetLabel = NoSourceText
|
| 109 | - , staticTargetUnit = unit
|
|
| 107 | + , staticTargetUnit = TargetIsInThisUnit
|
|
| 110 | 108 | }
|
| 111 | 109 | target = StaticTarget stExt lbl ForeignFunction
|
| 112 | 110 | the_fcall = CCall (CCallSpec target CCallConv may_gc)
|
| ... | ... | @@ -24,7 +24,7 @@ import GHC.HsToCore.Monad |
| 24 | 24 | |
| 25 | 25 | import GHC.Hs
|
| 26 | 26 | import GHC.Types.Id
|
| 27 | -import GHC.Types.ForeignCall
|
|
| 27 | +import GHC.Types.ForeignCall (ExportLinking(..))
|
|
| 28 | 28 | import GHC.Types.ForeignStubs
|
| 29 | 29 | import GHC.Unit.Module
|
| 30 | 30 | import GHC.Core.Coercion
|
| ... | ... | @@ -93,7 +93,7 @@ dsForeigns' fos = do |
| 93 | 93 | , fd_e_ext = co
|
| 94 | 94 | , fd_fe = CExport _
|
| 95 | 95 | (L _ (CExportStatic ext_nm cconv)) }) = do
|
| 96 | - (h, c, _, ids, bs) <- dsFExport id co ext_nm cconv False
|
|
| 96 | + (h, c, _, ids, bs) <- dsFExport id co ext_nm cconv ExportIsStatic
|
|
| 97 | 97 | return (h, c, ids, bs)
|
| 98 | 98 | |
| 99 | 99 | {-
|
| ... | ... | @@ -165,7 +165,7 @@ dsFExport :: Id -- Either the exported Id, |
| 165 | 165 | -- from C, and its representation type
|
| 166 | 166 | -> CLabelString -- The name to export to C land
|
| 167 | 167 | -> CCallConv
|
| 168 | - -> Bool -- True => foreign export dynamic
|
|
| 168 | + -> ExportLinking -- True => foreign export dynamic
|
|
| 169 | 169 | -- so invoke IO action that's hanging off
|
| 170 | 170 | -- the first argument's stable pointer
|
| 171 | 171 | -> DsM ( CHeader -- contents of Module_stub.h
|
| ... | ... | @@ -72,9 +72,9 @@ dsJsFExport |
| 72 | 72 | -- from C, and its representation type
|
| 73 | 73 | -> CLabelString -- The name to export to C land
|
| 74 | 74 | -> CCallConv
|
| 75 | - -> Bool -- True => foreign export dynamic
|
|
| 76 | - -- so invoke IO action that's hanging off
|
|
| 77 | - -- the first argument's stable pointer
|
|
| 75 | + -> ExportLinking -- If foreign export is dynamic
|
|
| 76 | + -- then invoke IO action that's hanging off
|
|
| 77 | + -- the first argument's stable pointer
|
|
| 78 | 78 | -> DsM ( CHeader -- contents of Module_stub.h
|
| 79 | 79 | , CStub -- contents of Module_stub.c
|
| 80 | 80 | , String -- string describing type to pass to createAdj.
|
| ... | ... | @@ -87,9 +87,9 @@ dsJsFExport fn_id co ext_name cconv isDyn = do |
| 87 | 87 | (fe_arg_tys', orig_res_ty) = tcSplitFunTys sans_foralls
|
| 88 | 88 | -- We must use tcSplits here, because we want to see
|
| 89 | 89 | -- the (IO t) in the corner of the type!
|
| 90 | - fe_arg_tys = case target_kind of
|
|
| 91 | - ForeignFunction -> tail fe_arg_tys'
|
|
| 92 | - _ -> fe_arg_tys'
|
|
| 90 | + (fe_arg_tys, m_fn_id) = case isDyn of
|
|
| 91 | + ExportIsDynamic -> (tail fe_arg_tys', Nothing)
|
|
| 92 | + ExportIsStatic -> (fe_arg_tys', Just fn_id)
|
|
| 93 | 93 | |
| 94 | 94 | -- Look at the result type of the exported function, orig_res_ty
|
| 95 | 95 | -- If it's IO t, return (t, True)
|
| ... | ... | @@ -101,8 +101,7 @@ dsJsFExport fn_id co ext_name cconv isDyn = do |
| 101 | 101 | Nothing -> (orig_res_ty, False)
|
| 102 | 102 | platform <- targetPlatform <$> getDynFlags
|
| 103 | 103 | return $
|
| 104 | - mkFExportJSBits platform ext_name
|
|
| 105 | - (if isDyn then Nothing else Just fn_id)
|
|
| 104 | + mkFExportJSBits platform ext_name m_fn_id
|
|
| 106 | 105 | (map scaledThing fe_arg_tys) res_ty is_IO_res_ty cconv
|
| 107 | 106 | |
| 108 | 107 | mkFExportJSBits
|
| ... | ... | @@ -231,7 +230,7 @@ dsJsImport |
| 231 | 230 | -> CImportSpec GhcTc
|
| 232 | 231 | -> CCallConv
|
| 233 | 232 | -> Safety
|
| 234 | - -> Maybe Header
|
|
| 233 | + -> Maybe (Header GhcTc)
|
|
| 235 | 234 | -> DsM ([Binding], CHeader, CStub)
|
| 236 | 235 | dsJsImport id co (CLabel cid) _ _ _ = do
|
| 237 | 236 | let ty = coercionLKind co
|
| ... | ... | @@ -283,7 +282,7 @@ dsJsFExportDynamic id co0 cconv = do |
| 283 | 282 | export_ty = mkVisFunTyMany stable_ptr_ty arg_ty
|
| 284 | 283 | bindIOId <- dsLookupGlobalId bindIOName
|
| 285 | 284 | stbl_value <- newSysLocalMDs stable_ptr_ty
|
| 286 | - (h_code, c_code, typestring) <- dsJsFExport id (mkRepReflCo export_ty) fe_nm cconv True
|
|
| 285 | + (h_code, c_code, typestring) <- dsJsFExport id (mkRepReflCo export_ty) fe_nm cconv ExportIsDynamic
|
|
| 287 | 286 | let
|
| 288 | 287 | {-
|
| 289 | 288 | The arguments to the external function which will
|
| ... | ... | @@ -300,7 +299,7 @@ dsJsFExportDynamic id co0 cconv = do |
| 300 | 299 | -- (probably in the RTS.)
|
| 301 | 300 | adjustor = fsLit "createAdjustor"
|
| 302 | 301 | |
| 303 | - ccall_adj <- dsCCall adjustor (moduleUnit mod) adj_args PlayRisky (mkTyConApp io_tc [res_ty])
|
|
| 302 | + ccall_adj <- dsCCall adjustor adj_args PlayRisky (mkTyConApp io_tc [res_ty])
|
|
| 304 | 303 | -- PlayRisky: the adjustor doesn't allocate in the Haskell heap or do a callback
|
| 305 | 304 | |
| 306 | 305 | let io_app = mkLams tvs $
|
| ... | ... | @@ -321,7 +320,7 @@ dsJsFExportDynamic id co0 cconv = do |
| 321 | 320 | toJsName :: Id -> String
|
| 322 | 321 | toJsName i = renderWithContext defaultSDocContext (pprCode (ppr (idName i)))
|
| 323 | 322 | |
| 324 | -dsJsCall :: Id -> Coercion -> ForeignCall -> Maybe Header
|
|
| 323 | +dsJsCall :: Id -> Coercion -> ForeignCall -> Maybe (Header GhcTc)
|
|
| 325 | 324 | -> DsM ([(Id, Expr TyVar)], CHeader, CStub)
|
| 326 | 325 | dsJsCall fn_id co (CCall (CCallSpec target cconv safety)) _mDeclHeader = do
|
| 327 | 326 | let
|
| ... | ... | @@ -650,7 +649,7 @@ mkJsCall u tgt args t = mkFCall u ccall args t |
| 650 | 649 | where
|
| 651 | 650 | stExt = StaticTargetGhc
|
| 652 | 651 | { staticTargetLabel = NoSourceText
|
| 653 | - , staticTargetUnit = ghcInternalUnit
|
|
| 652 | + , staticTargetUnit = TargetIsInThat ghcInternalUnit
|
|
| 654 | 653 | }
|
| 655 | 654 | ccall = CCall $ CCallSpec
|
| 656 | 655 | (StaticTarget stExt tgt ForeignFunction)
|
| ... | ... | @@ -42,7 +42,6 @@ import GHC.Types.Name |
| 42 | 42 | import GHC.Types.SourceText
|
| 43 | 43 | import GHC.Types.SrcLoc
|
| 44 | 44 | import GHC.Types.Var
|
| 45 | -import GHC.Unit
|
|
| 46 | 45 | import GHC.Utils.Outputable
|
| 47 | 46 | import GHC.Utils.Panic
|
| 48 | 47 | |
| ... | ... | @@ -131,7 +130,7 @@ dsWasmJSDynamicExport :: |
| 131 | 130 | Synchronicity ->
|
| 132 | 131 | Id ->
|
| 133 | 132 | Coercion ->
|
| 134 | - Unit ->
|
|
| 133 | + CCallStaticTargetUnit ->
|
|
| 135 | 134 | DsM ([Binding], CHeader, CStub, [Id])
|
| 136 | 135 | dsWasmJSDynamicExport sync fn_id co unitId = do
|
| 137 | 136 | sp_tycon <- dsLookupTyCon stablePtrTyConName
|
| ... | ... | @@ -308,7 +307,7 @@ dsWasmJSStaticImport :: |
| 308 | 307 | Id ->
|
| 309 | 308 | Coercion ->
|
| 310 | 309 | String ->
|
| 311 | - Unit ->
|
|
| 310 | + CCallStaticTargetUnit ->
|
|
| 312 | 311 | Synchronicity ->
|
| 313 | 312 | DsM ([Binding], CHeader, CStub)
|
| 314 | 313 | dsWasmJSStaticImport fn_id co js_src' unitId sync = do
|
| ... | ... | @@ -399,7 +398,7 @@ uniqueCFunName = do |
| 399 | 398 | mkWrapperName cfun_num "ghc_wasm_jsffi" ""
|
| 400 | 399 | |
| 401 | 400 | importBindingRHS ::
|
| 402 | - Unit ->
|
|
| 401 | + CCallStaticTargetUnit ->
|
|
| 403 | 402 | FastString ->
|
| 404 | 403 | [TyVar] ->
|
| 405 | 404 | [Scaled Type] ->
|
| ... | ... | @@ -423,7 +423,7 @@ rnHsForeignDecl (ForeignExport { fd_name = name, fd_sig_ty = ty, fd_fe = spec }) |
| 423 | 423 | --
|
| 424 | 424 | patchForeignImport :: Unit -> (ForeignImport GhcPs) -> (ForeignImport GhcRn)
|
| 425 | 425 | patchForeignImport unit (CImport ext cconv safety fs spec)
|
| 426 | - = CImport ext cconv safety fs (patchCImportSpec unit spec)
|
|
| 426 | + = CImport ext cconv safety (renameHeader <$> fs) (patchCImportSpec unit spec)
|
|
| 427 | 427 | |
| 428 | 428 | patchCImportSpec :: Unit -> CImportSpec GhcPs -> CImportSpec GhcRn
|
| 429 | 429 | patchCImportSpec unit = \case
|
| ... | ... | @@ -437,7 +437,7 @@ patchCCallTarget unit = \case |
| 437 | 437 | StaticTarget sTxt label targetKind ->
|
| 438 | 438 | let ext = StaticTargetGhc
|
| 439 | 439 | { staticTargetLabel = sTxt
|
| 440 | - , staticTargetUnit = unit
|
|
| 440 | + , staticTargetUnit = TargetIsInThat unit
|
|
| 441 | 441 | }
|
| 442 | 442 | in StaticTarget ext label targetKind
|
| 443 | 443 | |
| ... | ... | @@ -2037,7 +2037,7 @@ rnDataDefn doc (HsDataDefn { dd_cType = cType, dd_ctxt = context, dd_cons = cond |
| 2037 | 2037 | }
|
| 2038 | 2038 | where
|
| 2039 | 2039 | rn_ctype :: CType GhcPs -> CType GhcRn
|
| 2040 | - rn_ctype (CType x y z) = CType x y z
|
|
| 2040 | + rn_ctype (CType x y z) = CType x (renameHeader <$> y) z
|
|
| 2041 | 2041 | h98_style = not $ anyLConIsGadt condecls -- Note [Stupid theta]
|
| 2042 | 2042 | |
| 2043 | 2043 | rn_derivs ds
|
| ... | ... | @@ -27,8 +27,6 @@ import GHC.Cmm.Utils |
| 27 | 27 | import GHC.Platform
|
| 28 | 28 | import GHC.Platform.Profile
|
| 29 | 29 | |
| 30 | -import GHC.Hs.Extension ( GhcTc )
|
|
| 31 | - |
|
| 32 | 30 | import GHCi.FFI
|
| 33 | 31 | import GHC.Types.Basic
|
| 34 | 32 | import GHC.Utils.Outputable
|
| ... | ... | @@ -671,8 +669,8 @@ schemeT d s p (StgOpApp (StgPrimOp op) args _ty) = do |
| 671 | 669 | -- Otherwise we have to do a call to the primop wrapper instead :(
|
| 672 | 670 | _ -> doTailCall d s p (primOpId op) (reverse args)
|
| 673 | 671 | |
| 674 | -schemeT d s p (StgOpApp (StgPrimCallOp (PrimCall label unit)) args result_ty)
|
|
| 675 | - = generatePrimCall d s p label unit result_ty args
|
|
| 672 | +schemeT d s p (StgOpApp (StgPrimCallOp (PrimCall label _)) args result_ty)
|
|
| 673 | + = generatePrimCall d s p label result_ty args
|
|
| 676 | 674 | |
| 677 | 675 | schemeT d s p (StgConApp con _cn args _tys)
|
| 678 | 676 | -- Case 2: Unboxed tuple
|
| ... | ... | @@ -1869,11 +1867,10 @@ generatePrimCall |
| 1869 | 1867 | -> Sequel
|
| 1870 | 1868 | -> BCEnv
|
| 1871 | 1869 | -> CLabelString -- where to call
|
| 1872 | - -> Unit
|
|
| 1873 | 1870 | -> Type
|
| 1874 | 1871 | -> [StgArg] -- args (atoms)
|
| 1875 | 1872 | -> BcM BCInstrList
|
| 1876 | -generatePrimCall d s p target _mb_unit _result_ty args
|
|
| 1873 | +generatePrimCall d s p target _result_ty args
|
|
| 1877 | 1874 | = do
|
| 1878 | 1875 | profile <- getProfile
|
| 1879 | 1876 | let
|
| ... | ... | @@ -1931,13 +1928,13 @@ generateCCall |
| 1931 | 1928 | :: StackDepth
|
| 1932 | 1929 | -> Sequel
|
| 1933 | 1930 | -> BCEnv
|
| 1934 | - -> CCallSpec GhcTc -- where to call
|
|
| 1931 | + -> CCallSpec -- where to call
|
|
| 1935 | 1932 | -> Type
|
| 1936 | 1933 | -> [StgArg] -- args (atoms)
|
| 1937 | 1934 | -> BcM BCInstrList
|
| 1938 | 1935 | generateCCall d0 s p (CCallSpec target PrimCallConv _) result_ty args
|
| 1939 | - | (StaticTarget ext label _) <- target
|
|
| 1940 | - = generatePrimCall d0 s p label (staticTargetUnit ext) result_ty args
|
|
| 1936 | + | (StaticTarget _ label _) <- target
|
|
| 1937 | + = generatePrimCall d0 s p label result_ty args
|
|
| 1941 | 1938 | | otherwise
|
| 1942 | 1939 | = panic "GHC.StgToByteCode.generateCCall: primcall convention only supports static targets"
|
| 1943 | 1940 | generateCCall d0 s p (CCallSpec target _ safety) result_ty args
|
| ... | ... | @@ -2643,7 +2640,7 @@ isFollowableArg P = True |
| 2643 | 2640 | isFollowableArg _ = False
|
| 2644 | 2641 | |
| 2645 | 2642 | -- | Indicate if the calling convention is supported
|
| 2646 | -isSupportedCConv :: CCallSpec p -> Bool
|
|
| 2643 | +isSupportedCConv :: CCallSpec -> Bool
|
|
| 2647 | 2644 | isSupportedCConv (CCallSpec _ cconv _) = case cconv of
|
| 2648 | 2645 | CCallConv -> True -- we explicitly pattern match on every
|
| 2649 | 2646 | StdCallConv -> False -- convention to ensure that a warning
|
| ... | ... | @@ -81,8 +81,9 @@ cgForeignCall (CCall (CCallSpec target cconv safety)) typ stg_args res_ty |
| 81 | 81 | StaticTarget _ _ ForeignValue ->
|
| 82 | 82 | panic "cgForeignCall: unexpected FFI value import"
|
| 83 | 83 | StaticTarget ext lbl ForeignFunction ->
|
| 84 | - let labelSource =
|
|
| 85 | - ForeignLabelInPackage . toUnitId $ staticTargetUnit ext
|
|
| 84 | + let labelSource = case staticTargetUnit ext of
|
|
| 85 | + TargetIsInThisUnit -> ForeignLabelInThisPackage
|
|
| 86 | + TargetIsInThat unit -> ForeignLabelInPackage $ toUnitId unit
|
|
| 86 | 87 | in ( unzip cmm_args
|
| 87 | 88 | , CmmLit
|
| 88 | 89 | (CmmLabel (mkForeignLabel lbl labelSource IsFunction)))
|
| ... | ... | @@ -197,7 +197,6 @@ import GHC.Types.Basic |
| 197 | 197 | import GHC.Types.Error
|
| 198 | 198 | import GHC.Types.Avail
|
| 199 | 199 | import GHC.Types.Hint
|
| 200 | -import GHC.Types.ForeignCall ( CLabelString )
|
|
| 201 | 200 | import GHC.Types.Id.Info ( RecSelParent(..) )
|
| 202 | 201 | import GHC.Types.InlinePragma (InlinePragma(..))
|
| 203 | 202 | import GHC.Types.Name (NamedThing(..), Name, OccName, getSrcLoc, getSrcSpan)
|
| ... | ... | @@ -292,7 +292,7 @@ tcCheckFIType arg_tys res_ty idecl@(CImport src (L lc cconv) safety mh (CLabel c |
| 292 | 292 | check (isFFILabelTy (mkScaledFunTys arg_tys res_ty))
|
| 293 | 293 | (TcRnIllegalForeignType Nothing)
|
| 294 | 294 | cconv' <- checkCConv (Right idecl) cconv
|
| 295 | - return $ CImport src (L lc cconv') safety mh (CLabel cLabel)
|
|
| 295 | + return $ CImport src (L lc cconv') safety (typeCheckHeader <$> mh) (CLabel cLabel)
|
|
| 296 | 296 | |
| 297 | 297 | tcCheckFIType arg_tys res_ty idecl@(CImport src (L lc cconv) safety mh CWrapper) = do
|
| 298 | 298 | -- Foreign wrapper (former foreign export dynamic)
|
| ... | ... | @@ -310,7 +310,7 @@ tcCheckFIType arg_tys res_ty idecl@(CImport src (L lc cconv) safety mh CWrapper) |
| 310 | 310 | where
|
| 311 | 311 | (arg1_tys, res1_ty) = tcSplitFunTys arg1_ty
|
| 312 | 312 | _ -> addErrTc (TcRnIllegalForeignType Nothing OneArgExpected)
|
| 313 | - return (CImport src (L lc cconv') safety mh CWrapper)
|
|
| 313 | + return (CImport src (L lc cconv') safety (typeCheckHeader <$> mh) CWrapper)
|
|
| 314 | 314 | |
| 315 | 315 | tcCheckFIType arg_tys res_ty idecl@(CImport src (L lc cconv) (L ls safety) mh
|
| 316 | 316 | (CFunction target))
|
| ... | ... | @@ -361,7 +361,7 @@ tcCheckFIType arg_tys res_ty idecl@(CImport src (L lc cconv) (L ls safety) mh |
| 361 | 361 | _ -> return ()
|
| 362 | 362 | return $ cImport' cconv'
|
| 363 | 363 | where
|
| 364 | - cImport' cConv = CImport src (L lc cConv) cSafe mh cFun
|
|
| 364 | + cImport' cConv = CImport src (L lc cConv) cSafe (typeCheckHeader <$> mh) cFun
|
|
| 365 | 365 | cFun = CFunction $ rnCCallTarget target
|
| 366 | 366 | cSafe = L ls safety
|
| 367 | 367 |
| ... | ... | @@ -75,7 +75,7 @@ import GHC.Core.TyCon |
| 75 | 75 | import GHC.Core.DataCon
|
| 76 | 76 | import GHC.Core.Unify
|
| 77 | 77 | |
| 78 | -import GHC.Types.ForeignCall ( CType(..) )
|
|
| 78 | +import GHC.Types.ForeignCall ( typeCheckCType )
|
|
| 79 | 79 | import GHC.Types.Id
|
| 80 | 80 | import GHC.Types.Id.Make
|
| 81 | 81 | import GHC.Types.Var
|
| ... | ... | @@ -3599,13 +3599,11 @@ tcDataDefn err_ctxt roles_info tc_name |
| 3599 | 3599 | { data_cons <- tcConDecls DDataType rec_tycon tc_bndrs res_kind cons
|
| 3600 | 3600 | ; tc_rhs <- mk_tc_rhs hsc_src rec_tycon data_cons
|
| 3601 | 3601 | ; tc_rep_nm <- newTyConRepName tc_name
|
| 3602 | - ; let tc_ctype :: CType GhcRn -> CType GhcTc
|
|
| 3603 | - tc_ctype (CType x y z) = CType x y z
|
|
| 3604 | 3602 | ; return (mkAlgTyCon tc_name kind
|
| 3605 | 3603 | bndrs nb_eta
|
| 3606 | 3604 | res_kind
|
| 3607 | 3605 | (roles_info tc_name)
|
| 3608 | - (fmap (tc_ctype . unLoc) cType)
|
|
| 3606 | + (fmap (typeCheckCType . unLoc) cType)
|
|
| 3609 | 3607 | stupid_theta tc_rhs
|
| 3610 | 3608 | (VanillaAlgTyCon tc_rep_nm)
|
| 3611 | 3609 | gadt_syntax)
|
| ... | ... | @@ -69,7 +69,7 @@ import GHC.Types.Var as Var |
| 69 | 69 | import GHC.Types.Var.Env
|
| 70 | 70 | import GHC.Types.Var.Set
|
| 71 | 71 | import GHC.Types.Basic
|
| 72 | -import GHC.Types.ForeignCall ( CType(..) )
|
|
| 72 | +import GHC.Types.ForeignCall ( typeCheckCType )
|
|
| 73 | 73 | import GHC.Types.Id
|
| 74 | 74 | import GHC.Types.InlinePragma
|
| 75 | 75 | import GHC.Types.SourceFile
|
| ... | ... | @@ -827,13 +827,11 @@ tcDataFamInstDecl mb_clsinfo tv_skol_env |
| 827 | 827 | |
| 828 | 828 | -- NB: Use the full ty_binders from the pats. See bullet toward
|
| 829 | 829 | -- the end of Note [Data type families] in GHC.Core.TyCon
|
| 830 | - tc_ctype :: CType GhcRn -> CType GhcTc
|
|
| 831 | - tc_ctype (CType x y z) = CType x y z
|
|
| 832 | 830 | rep_tc = mkAlgTyCon rep_tc_name user_kind
|
| 833 | 831 | ty_binders (length extra_tcbs)
|
| 834 | 832 | res_kind
|
| 835 | 833 | (map (const Nominal) ty_binders)
|
| 836 | - (fmap (tc_ctype . unLoc) cType) stupid_theta
|
|
| 834 | + (fmap (typeCheckCType . unLoc) cType) stupid_theta
|
|
| 837 | 835 | tc_rhs parent
|
| 838 | 836 | gadt_syntax
|
| 839 | 837 | -- We always assume that indexed types are recursive. Why?
|
| ... | ... | @@ -39,7 +39,6 @@ import GHC.Utils.Outputable ( Outputable(..) ) |
| 39 | 39 | |
| 40 | 40 | import Language.Haskell.Syntax
|
| 41 | 41 | import Language.Haskell.Syntax.Basic ( FieldLabelString(..) )
|
| 42 | -import Language.Haskell.Syntax.Decls.Foreign ( ForeignDecl(..) )
|
|
| 43 | 42 | import GHC.Boot.TH.Syntax qualified as TH
|
| 44 | 43 | |
| 45 | 44 | import qualified Data.List.NonEmpty as NE
|
| ... | ... | @@ -39,6 +39,8 @@ module GHC.Types.ForeignCall ( |
| 39 | 39 | ForeignExport(..),
|
| 40 | 40 | -- ** Specification
|
| 41 | 41 | CExportSpec(..),
|
| 42 | + -- ** Linking flags
|
|
| 43 | + ExportLinking(..),
|
|
| 42 | 44 | |
| 43 | 45 | -- * Foreign import types
|
| 44 | 46 | -- ** Data-type
|
| ... | ... | @@ -47,6 +49,7 @@ module GHC.Types.ForeignCall ( |
| 47 | 49 | CCallTarget(..),
|
| 48 | 50 | -- *** GHC extension point
|
| 49 | 51 | StaticTargetGhc(..),
|
| 52 | + CCallStaticTargetUnit(..),
|
|
| 50 | 53 | -- *** Queries
|
| 51 | 54 | isDynamicTarget,
|
| 52 | 55 | -- ** Foreign target kind
|
| ... | ... | @@ -65,6 +68,8 @@ module GHC.Types.ForeignCall ( |
| 65 | 68 | -- *** Construction
|
| 66 | 69 | defaultCType,
|
| 67 | 70 | mkCType,
|
| 71 | + -- *** Conversion
|
|
| 72 | + typeCheckCType,
|
|
| 68 | 73 | -- *** GHC extension point
|
| 69 | 74 | CTypeGhc(..),
|
| 70 | 75 | |
| ... | ... | @@ -83,6 +88,9 @@ module GHC.Types.ForeignCall ( |
| 83 | 88 | pprCLabelString,
|
| 84 | 89 | -- ** Header
|
| 85 | 90 | Header(..),
|
| 91 | + -- *** Conversion
|
|
| 92 | + renameHeader,
|
|
| 93 | + typeCheckHeader,
|
|
| 86 | 94 | ) where
|
| 87 | 95 | |
| 88 | 96 | import GHC.Prelude
|
| ... | ... | @@ -101,7 +109,6 @@ import Language.Haskell.Syntax.Extension |
| 101 | 109 | import Data.Char
|
| 102 | 110 | import Data.Data (Data)
|
| 103 | 111 | import Data.Functor ((<&>))
|
| 104 | -import Data.String (fromString)
|
|
| 105 | 112 | |
| 106 | 113 | import Control.DeepSeq (NFData(..))
|
| 107 | 114 | |
| ... | ... | @@ -113,8 +120,8 @@ import Control.DeepSeq (NFData(..)) |
| 113 | 120 | ************************************************************************
|
| 114 | 121 | -}
|
| 115 | 122 | |
| 116 | -newtype ForeignCall = CCall (CCallSpec GhcTc)
|
|
| 117 | - deriving ( Eq )
|
|
| 123 | +newtype ForeignCall = CCall CCallSpec
|
|
| 124 | + deriving (Eq)
|
|
| 118 | 125 | |
| 119 | 126 | isSafeForeignCall :: ForeignCall -> Bool
|
| 120 | 127 | isSafeForeignCall (CCall (CCallSpec _ _ safe)) = playSafe safe
|
| ... | ... | @@ -141,12 +148,12 @@ playInterruptible _ = False |
| 141 | 148 | ************************************************************************
|
| 142 | 149 | -}
|
| 143 | 150 | |
| 144 | -data CCallSpec pass
|
|
| 145 | - = CCallSpec (CCallTarget pass) -- What to call
|
|
| 146 | - CCallConv -- Calling convention to use.
|
|
| 147 | - Safety
|
|
| 148 | - |
|
| 149 | -deriving instance forall p. IsPass p => Eq (CCallSpec (GhcPass p))
|
|
| 151 | +data CCallSpec
|
|
| 152 | + = CCallSpec
|
|
| 153 | + (CCallTarget GhcTc) -- What to call
|
|
| 154 | + CCallConv -- Calling convention to use.
|
|
| 155 | + Safety
|
|
| 156 | + deriving (Eq)
|
|
| 150 | 157 | |
| 151 | 158 | isDynamicTarget :: CCallTarget p -> Bool
|
| 152 | 159 | isDynamicTarget DynamicTarget{} = True
|
| ... | ... | @@ -180,7 +187,7 @@ isCLabelString lbl |
| 180 | 187 | |
| 181 | 188 | -- Printing into C files:
|
| 182 | 189 | |
| 183 | -instance forall p. IsPass p => Outputable (CCallSpec (GhcPass p)) where
|
|
| 190 | +instance Outputable CCallSpec where
|
|
| 184 | 191 | ppr (CCallSpec fun cconv safety)
|
| 185 | 192 | = hcat [ whenPprDebug callconv, ppr_fun fun, text " ::" ]
|
| 186 | 193 | where
|
| ... | ... | @@ -191,15 +198,14 @@ instance forall p. IsPass p => Outputable (CCallSpec (GhcPass p)) where |
| 191 | 198 | |
| 192 | 199 | ppr_fun = \case
|
| 193 | 200 | DynamicTarget{} -> text "__ffi_dyn_ccall" <> gc_suf <+> text "\"\""
|
| 194 | - st@(StaticTarget _ label isFun) ->
|
|
| 201 | + StaticTarget ext label isFun ->
|
|
| 195 | 202 | let pCallType = case isFun of
|
| 196 | 203 | ForeignValue -> text "__ffi_static_ccall_value"
|
| 197 | 204 | ForeignFunction -> text "__ffi_static_ccall"
|
| 198 | - (srcTxt, pPkgId) = case ghcPass @p of
|
|
| 199 | - GhcPs | StaticTarget ext _ _ <- st -> (ext, empty)
|
|
| 200 | - GhcRn | StaticTarget ext _ _ <- st -> (staticTargetLabel ext, ppr $ staticTargetUnit ext)
|
|
| 201 | - GhcTc | StaticTarget ext _ _ <- st -> (staticTargetLabel ext, ppr $ staticTargetUnit ext)
|
|
| 202 | - |
|
| 205 | + pprUnit ext = case staticTargetUnit ext of
|
|
| 206 | + TargetIsInThisUnit -> empty
|
|
| 207 | + TargetIsInThat unit -> ppr unit
|
|
| 208 | + (srcTxt, pPkgId) = (staticTargetLabel ext, pprUnit ext)
|
|
| 203 | 209 | in pCallType
|
| 204 | 210 | <> gc_suf
|
| 205 | 211 | <+> pPkgId
|
| ... | ... | @@ -209,12 +215,21 @@ instance forall p. IsPass p => Outputable (CCallSpec (GhcPass p)) where |
| 209 | 215 | |
| 210 | 216 | defaultCType :: String -> CType (GhcPass p)
|
| 211 | 217 | defaultCType =
|
| 212 | - CType (CTypeGhc NoSourceText NoSourceText) Nothing . fromString
|
|
| 218 | + CType (CTypeGhc NoSourceText NoSourceText) Nothing . fsLit
|
|
| 213 | 219 | |
| 214 | -mkCType :: SourceText -> SourceText -> Maybe Header -> FastString -> CType (GhcPass p)
|
|
| 220 | +mkCType :: SourceText -> SourceText -> Maybe (Header (GhcPass p)) -> FastString -> CType (GhcPass p)
|
|
| 215 | 221 | mkCType x y m =
|
| 216 | 222 | CType (CTypeGhc x y) m
|
| 217 | 223 | |
| 224 | +typeCheckCType :: CType GhcRn -> CType GhcTc
|
|
| 225 | +typeCheckCType (CType x y z) = CType x (typeCheckHeader <$> y) z
|
|
| 226 | + |
|
| 227 | +typeCheckHeader :: Header GhcRn -> Header GhcTc
|
|
| 228 | +typeCheckHeader (Header a b) = Header a b
|
|
| 229 | + |
|
| 230 | +renameHeader :: Header GhcPs -> Header GhcRn
|
|
| 231 | +renameHeader (Header a b) = Header a b
|
|
| 232 | + |
|
| 218 | 233 | {-
|
| 219 | 234 | ************************************************************************
|
| 220 | 235 | * *
|
| ... | ... | @@ -227,7 +242,7 @@ instance Binary ForeignCall where |
| 227 | 242 | put_ bh (CCall aa) = put_ bh aa
|
| 228 | 243 | get bh = do aa <- get bh; return (CCall aa)
|
| 229 | 244 | |
| 230 | -instance forall p. IsPass p => Binary (CCallSpec (GhcPass p)) where
|
|
| 245 | +instance Binary CCallSpec where
|
|
| 231 | 246 | put_ bh (CCallSpec aa ab ac) = do
|
| 232 | 247 | put_ bh aa
|
| 233 | 248 | put_ bh ab
|
| ... | ... | @@ -241,7 +256,7 @@ instance forall p. IsPass p => Binary (CCallSpec (GhcPass p)) where |
| 241 | 256 | instance NFData ForeignCall where
|
| 242 | 257 | rnf (CCall c) = rnf c
|
| 243 | 258 | |
| 244 | -instance forall p. IsPass p => NFData (CCallSpec (GhcPass p)) where
|
|
| 259 | +instance NFData CCallSpec where
|
|
| 245 | 260 | rnf (CCallSpec t c s) = rnf t `seq` rnf c `seq` rnf s
|
| 246 | 261 | |
| 247 | 262 | instance Binary CCallConv where
|
| ... | ... | @@ -264,12 +279,27 @@ instance Binary CCallConv where |
| 264 | 279 | 3 -> return CApiConv
|
| 265 | 280 | _ -> return JavaScriptCallConv
|
| 266 | 281 | |
| 267 | --- If Nothing, then it's taken to be in the current package.
|
|
| 282 | +-- |
|
|
| 283 | +-- Determine whether the JavaScript Foreign Function export should be
|
|
| 284 | +-- dynamically linked or statically linked.
|
|
| 285 | +data ExportLinking
|
|
| 286 | + = ExportIsDynamic
|
|
| 287 | + | ExportIsStatic
|
|
| 288 | + |
|
| 289 | +-- |
|
|
| 290 | +-- Which compilation 'Unit' is the static target in,
|
|
| 291 | +-- either it is in this currently compiling compilation 'Unit',
|
|
| 292 | +-- or it is in /that other/, compilation 'Unit'.
|
|
| 293 | +data CCallStaticTargetUnit
|
|
| 294 | + = TargetIsInThisUnit -- ^ In this current 'Unit'.
|
|
| 295 | + | TargetIsInThat Unit -- ^ In that other 'Unit'.
|
|
| 296 | + deriving (Data, Eq)
|
|
| 297 | + |
|
| 268 | 298 | data StaticTargetGhc = StaticTargetGhc
|
| 269 | 299 | { staticTargetLabel :: SourceText
|
| 270 | - , staticTargetUnit :: CCallStaticUnit
|
|
| 300 | + , staticTargetUnit :: CCallStaticTargetUnit
|
|
| 271 | 301 | -- ^ What package the function is in.
|
| 272 | - -- If 'CCallStaticThisUnit', then it's taken to be in the current package
|
|
| 302 | + -- If 'CCallStaticTargetUnit', then it's taken to be in the current package
|
|
| 273 | 303 | -- Note: This information is only used for PrimCalls on Windows.
|
| 274 | 304 | -- See CLabel.labelDynamic and CoreToStg.coreToStgApp
|
| 275 | 305 | -- for the difference in representation between PrimCalls
|
| ... | ... | @@ -290,13 +320,36 @@ type instance XStaticTarget GhcTc = StaticTargetGhc |
| 290 | 320 | type instance XDynamicTarget (GhcPass p) = NoExtField
|
| 291 | 321 | type instance XXCCallTarget (GhcPass p) = DataConCantHappen
|
| 292 | 322 | |
| 293 | -type instance XCType (GhcPass p) = CTypeGhc
|
|
| 294 | -type instance XXCType (GhcPass p) = DataConCantHappen
|
|
| 323 | +type instance XCType (GhcPass p) = CTypeGhc
|
|
| 324 | +type instance XXCType (GhcPass p) = DataConCantHappen
|
|
| 325 | + |
|
| 326 | +type instance XHeader (GhcPass p) = SourceText
|
|
| 327 | +type instance XXHeader (GhcPass p) = DataConCantHappen
|
|
| 328 | + |
|
| 329 | +deriving instance Eq (Header (GhcPass p))
|
|
| 295 | 330 | |
| 296 | 331 | instance NFData (CType (GhcPass p)) where
|
| 297 | 332 | rnf (CType ext mh fs) =
|
| 298 | 333 | rnf ext `seq` rnf mh `seq` rnf fs
|
| 299 | 334 | |
| 335 | +instance NFData (Header (GhcPass p)) where
|
|
| 336 | + rnf (Header s h) =
|
|
| 337 | + rnf s `seq` rnf h
|
|
| 338 | + |
|
| 339 | +instance NFData CCallStaticTargetUnit where
|
|
| 340 | + rnf = \case
|
|
| 341 | + TargetIsInThisUnit -> ()
|
|
| 342 | + TargetIsInThat unit -> rnf unit
|
|
| 343 | + |
|
| 344 | +instance Binary CCallStaticTargetUnit where
|
|
| 345 | + put_ bh = \case
|
|
| 346 | + TargetIsInThisUnit -> putByte bh 0
|
|
| 347 | + TargetIsInThat unit -> putByte bh 1 *> put_ bh unit
|
|
| 348 | + |
|
| 349 | + get bh = getByte bh >>= \case
|
|
| 350 | + 0 -> pure TargetIsInThisUnit
|
|
| 351 | + _ -> TargetIsInThat <$> get bh
|
|
| 352 | + |
|
| 300 | 353 | instance NFData CTypeGhc where
|
| 301 | 354 | rnf st =
|
| 302 | 355 | rnf (cTypeSourceText st) `seq`
|
| ... | ... | @@ -406,7 +459,7 @@ instance Binary ForeignKind where |
| 406 | 459 | 0 -> ForeignValue
|
| 407 | 460 | _ -> ForeignFunction
|
| 408 | 461 | |
| 409 | -instance Binary Header where
|
|
| 462 | +instance Binary (Header (GhcPass p)) where
|
|
| 410 | 463 | put_ bh (Header s h) = put_ bh s >> put_ bh h
|
| 411 | 464 | get bh = do
|
| 412 | 465 | s <- get bh
|
| ... | ... | @@ -447,7 +500,7 @@ instance Outputable (CType (GhcPass p)) where |
| 447 | 500 | Nothing -> empty
|
| 448 | 501 | Just h -> ppr h
|
| 449 | 502 | |
| 450 | -instance Outputable Header where
|
|
| 503 | +instance Outputable (Header (GhcPass p)) where
|
|
| 451 | 504 | ppr (Header st h) = pprWithSourceText st (doubleQuotes $ ppr h)
|
| 452 | 505 | |
| 453 | 506 | instance Outputable Safety where
|
| ... | ... | @@ -51,12 +51,10 @@ module Language.Haskell.Syntax.Decls ( |
| 51 | 51 | -- ** Template haskell declaration splice
|
| 52 | 52 | SpliceDecoration(..),
|
| 53 | 53 | SpliceDecl(..), LSpliceDecl,
|
| 54 | -{-
|
|
| 55 | 54 | -- ** Foreign function interface declarations
|
| 56 | 55 | ForeignDecl(..), LForeignDecl, ForeignImport(..), ForeignExport(..),
|
| 57 | 56 | CCallConv(..), CCallTarget(..), CExportSpec(..), CImportSpec(..), CLabelString,
|
| 58 | 57 | CType(..), Header(..), Safety(..),
|
| 59 | --}
|
|
| 60 | 58 | -- ** Data-constructor declarations
|
| 61 | 59 | ConDecl(..), LConDecl,
|
| 62 | 60 | HsConDeclH98Details,
|
| ... | ... | @@ -61,19 +61,21 @@ module Language.Haskell.Syntax.Decls.Foreign ( |
| 61 | 61 | -- ** CType
|
| 62 | 62 | XCType,
|
| 63 | 63 | XXCType,
|
| 64 | + -- ** Header
|
|
| 65 | + XHeader,
|
|
| 66 | + XXHeader,
|
|
| 64 | 67 | ) where
|
| 65 | 68 | |
| 66 | 69 | import Language.Haskell.Syntax.Extension
|
| 67 | 70 | import Language.Haskell.Syntax.Type
|
| 68 | 71 | |
| 69 | 72 | import GHC.Data.FastString (FastString)
|
| 70 | -import GHC.Types.SourceText (SourceText)
|
|
| 71 | 73 | |
| 72 | 74 | import Control.DeepSeq
|
| 73 | 75 | import Data.Data hiding (TyCon, Fixity, Infix)
|
| 74 | 76 | import Data.Maybe
|
| 75 | 77 | import Data.Eq
|
| 76 | -import Prelude (Enum, Show, seq)
|
|
| 78 | +import Prelude (Enum, Show)
|
|
| 77 | 79 | |
| 78 | 80 | {-
|
| 79 | 81 | ************************************************************************
|
| ... | ... | @@ -120,27 +122,27 @@ data ForeignDecl pass |
| 120 | 122 | -- |
|
| 121 | 123 | -- Specification Of an imported external entity in dependence on the calling
|
| 122 | 124 | -- convention
|
| 123 | ---
|
|
| 124 | --- Import of a C entity
|
|
| 125 | ---
|
|
| 126 | --- * the two strings specifying a header file or library
|
|
| 127 | --- may be empty, which indicates the absence of a
|
|
| 128 | --- header or object specification (both are not used
|
|
| 129 | --- in the case of `CWrapper' and when `CFunction'
|
|
| 130 | --- has a dynamic target)
|
|
| 131 | ---
|
|
| 132 | --- * the calling convention is irrelevant for code
|
|
| 133 | --- generation in the case of `CLabel', but is needed
|
|
| 134 | --- for pretty printing
|
|
| 135 | ---
|
|
| 136 | --- * `Safety' is irrelevant for `CLabel' and `CWrapper'
|
|
| 137 | ---
|
|
| 138 | 125 | data ForeignImport pass
|
| 139 | - = CImport
|
|
| 126 | + = -- |
|
|
| 127 | + -- Import of a C entity
|
|
| 128 | + --
|
|
| 129 | + -- * the two strings specifying a header file or library
|
|
| 130 | + -- may be empty, which indicates the absence of a
|
|
| 131 | + -- header or object specification (both are not used
|
|
| 132 | + -- in the case of `CWrapper' and when `CFunction'
|
|
| 133 | + -- has a dynamic target)
|
|
| 134 | + --
|
|
| 135 | + -- * the calling convention is irrelevant for code
|
|
| 136 | + -- generation in the case of `CLabel', but is needed
|
|
| 137 | + -- for pretty printing
|
|
| 138 | + --
|
|
| 139 | + -- * `Safety' is irrelevant for `CLabel' and `CWrapper'
|
|
| 140 | + --
|
|
| 141 | + CImport
|
|
| 140 | 142 | (XCImport pass)
|
| 141 | 143 | (XRec pass CCallConv) -- ccall
|
| 142 | 144 | (XRec pass Safety) -- interruptible, safe or unsafe
|
| 143 | - (Maybe Header) -- name of C header
|
|
| 145 | + (Maybe (Header pass)) -- name of C header
|
|
| 144 | 146 | (CImportSpec pass) -- details of the C entity
|
| 145 | 147 | | XForeignImport !(XXForeignImport pass)
|
| 146 | 148 | |
| ... | ... | @@ -208,12 +210,6 @@ data CCallTarget pass |
| 208 | 210 | | DynamicTarget (XDynamicTarget pass)
|
| 209 | 211 | | XCCallTarget !(XXCCallTarget pass)
|
| 210 | 212 | |
| 211 | -deriving instance {-# OVERLAPPABLE #-} (
|
|
| 212 | - Eq (XStaticTarget pass),
|
|
| 213 | - Eq (XDynamicTarget pass),
|
|
| 214 | - Eq (XXCCallTarget pass)) =>
|
|
| 215 | - Eq (CCallTarget pass)
|
|
| 216 | - |
|
| 217 | 213 | data CExportSpec
|
| 218 | 214 | -- | foreign export ccall foo :: ty
|
| 219 | 215 | = CExportStatic
|
| ... | ... | @@ -227,33 +223,17 @@ type CLabelString = FastString -- A C label, completely unencoded |
| 227 | 223 | data CType pass
|
| 228 | 224 | = CType
|
| 229 | 225 | (XCType pass)
|
| 230 | - (Maybe Header) -- header to include for this type
|
|
| 226 | + (Maybe (Header pass)) -- header to include for this type
|
|
| 231 | 227 | FastString
|
| 232 | 228 | | XCType !(XXCType pass)
|
| 233 | 229 | |
| 234 | -deriving instance {-# OVERLAPPABLE #-}
|
|
| 235 | - ( Eq (XCType pass)
|
|
| 236 | - , Eq (XXCType pass)
|
|
| 237 | - ) =>
|
|
| 238 | - Eq (CType pass)
|
|
| 239 | - |
|
| 240 | -instance {-# OVERLAPPABLE #-}
|
|
| 241 | - ( NFData (XCType pass)
|
|
| 242 | - , NFData (XXCType pass)
|
|
| 243 | - ) => NFData (CType pass) where
|
|
| 244 | - rnf = \case
|
|
| 245 | - CType ext mh fs -> rnf ext `seq` rnf mh `seq` rnf fs
|
|
| 246 | - XCType ext -> rnf ext
|
|
| 247 | - |
|
| 248 | 230 | -- The filename for a C header file
|
| 249 | 231 | -- See Note [Pragma source text] in "GHC.Types.SourceText"
|
| 250 | -data Header = Header
|
|
| 251 | - SourceText -- pretty printing to EXT point
|
|
| 252 | - FastString
|
|
| 253 | - deriving (Eq, Data)
|
|
| 254 | - |
|
| 255 | -instance NFData Header where
|
|
| 256 | - rnf (Header s h) = rnf s `seq` rnf h
|
|
| 232 | +data Header pass
|
|
| 233 | + = Header
|
|
| 234 | + (XHeader pass)
|
|
| 235 | + FastString
|
|
| 236 | + | XHeader !(XXHeader pass)
|
|
| 257 | 237 | |
| 258 | 238 | data Safety
|
| 259 | 239 | = PlaySafe -- ^ Might invoke Haskell GC, or do a call back, or
|
| ... | ... | @@ -392,6 +392,11 @@ type family XXCCallTarget x |
| 392 | 392 | type family XCType x
|
| 393 | 393 | type family XXCType x
|
| 394 | 394 | |
| 395 | +-- -------------------------------------
|
|
| 396 | +-- Header type family
|
|
| 397 | +type family XHeader x
|
|
| 398 | +type family XXHeader x
|
|
| 399 | + |
|
| 395 | 400 | -- -------------------------------------
|
| 396 | 401 | -- ForeignDecl type families
|
| 397 | 402 | type family XForeignImport x
|
| ... | ... | @@ -29,7 +29,7 @@ import Data.Foldable (toList) |
| 29 | 29 | import Data.List (intercalate, isPrefixOf)
|
| 30 | 30 | import Data.Maybe
|
| 31 | 31 | import Data.Version
|
| 32 | -import GHC
|
|
| 32 | +import GHC hiding (Header)
|
|
| 33 | 33 | import GHC.Core.InstEnv
|
| 34 | 34 | import qualified GHC.Driver.DynFlags as DynFlags
|
| 35 | 35 | import GHC.Driver.Ppr
|
| ... | ... | @@ -27,7 +27,7 @@ import Data.List (sort) |
| 27 | 27 | import Data.List.NonEmpty (NonEmpty (..))
|
| 28 | 28 | import qualified Data.Map as Map
|
| 29 | 29 | import qualified Data.Maybe as Maybe
|
| 30 | -import GHC hiding (HsTypeGhcPsExt (..), fromMaybeContext)
|
|
| 30 | +import GHC hiding (Header, HsTypeGhcPsExt (..), fromMaybeContext)
|
|
| 31 | 31 | import GHC.Core.Type (Specificity (..))
|
| 32 | 32 | import GHC.Data.FastString (unpackFS)
|
| 33 | 33 | import GHC.Types.Name (getOccString, nameOccName, tidyNameOcc)
|
| ... | ... | @@ -24,7 +24,7 @@ module Haddock.Backends.Xhtml.DocMarkup |
| 24 | 24 | |
| 25 | 25 | import Data.List (intersperse)
|
| 26 | 26 | import Data.Maybe (fromMaybe)
|
| 27 | -import GHC
|
|
| 27 | +import GHC hiding (Header)
|
|
| 28 | 28 | import GHC.Types.Name
|
| 29 | 29 | import Text.XHtml hiding (name, p, quote)
|
| 30 | 30 |
| ... | ... | @@ -30,7 +30,7 @@ import Data.Functor |
| 30 | 30 | import Data.List (maximumBy, (\\))
|
| 31 | 31 | import Data.Ord
|
| 32 | 32 | import qualified Data.Set as Set
|
| 33 | -import GHC
|
|
| 33 | +import GHC hiding (Header)
|
|
| 34 | 34 | import GHC.Data.EnumSet as EnumSet
|
| 35 | 35 | import GHC.Data.FastString (unpackFS)
|
| 36 | 36 | import GHC.Driver.Session
|
| ... | ... | @@ -33,13 +33,14 @@ import qualified Data.Map.Strict as Map |
| 33 | 33 | import qualified Data.Set as Set
|
| 34 | 34 | import Data.Traversable (mapM)
|
| 35 | 35 | |
| 36 | -import GHC hiding (NoLink, HsTypeGhcPsExt (..))
|
|
| 36 | +import GHC hiding (Header, NoLink, HsTypeGhcPsExt (..))
|
|
| 37 | 37 | import GHC.Builtin.Types (eqTyCon_RDR, tupleDataConName, tupleTyConName)
|
| 38 | 38 | import GHC.Core.TyCon (tyConResKind)
|
| 39 | 39 | import GHC.Driver.DynFlags (getDynFlags)
|
| 40 | 40 | import GHC.Hs.Decls.Overlap (OverlapMode(..))
|
| 41 | 41 | import GHC.Types.Basic (TupleSort (..))
|
| 42 | -import GHC.Types.ForeignCall
|
|
| 42 | +import GHC.Types.ForeignCall hiding (Header)
|
|
| 43 | +import qualified GHC.Types.ForeignCall as Hs (Header(..))
|
|
| 43 | 44 | import GHC.Types.Name
|
| 44 | 45 | import GHC.Types.Name.Reader (RdrName (Exact))
|
| 45 | 46 | import Language.Haskell.Syntax.BooleanFormula(BooleanFormula(..))
|
| ... | ... | @@ -683,7 +684,10 @@ renameDataDefn |
| 683 | 684 | )
|
| 684 | 685 | |
| 685 | 686 | renameCType :: CType GhcRn -> CType DocNameI
|
| 686 | -renameCType (CType _ y z) = CType NoExtField y z
|
|
| 687 | +renameCType (CType _ y z) = CType NoExtField (renameHeader' <$> y) z
|
|
| 688 | + |
|
| 689 | +renameHeader' :: Hs.Header GhcRn -> Hs.Header DocNameI
|
|
| 690 | +renameHeader' (Hs.Header _ s) = Hs.Header NoExtField s
|
|
| 687 | 691 | |
| 688 | 692 | renameCon :: ConDecl GhcRn -> RnM (ConDecl DocNameI)
|
| 689 | 693 | renameCon
|
| ... | ... | @@ -834,7 +838,8 @@ renameForD (ForeignExport _ lname ltype x) = do |
| 834 | 838 | return (ForeignExport noExtField lname' ltype' (renameForE x))
|
| 835 | 839 | |
| 836 | 840 | renameForI :: ForeignImport GhcRn -> ForeignImport DocNameI
|
| 837 | -renameForI (CImport _ cconv safety mHeader spec) = CImport noExtField cconv safety mHeader (renameForISpec spec)
|
|
| 841 | +renameForI (CImport _ cconv safety mHeader spec) =
|
|
| 842 | + CImport noExtField cconv safety (renameHeader' <$> mHeader) (renameForISpec spec)
|
|
| 838 | 843 | |
| 839 | 844 | renameForE :: ForeignExport GhcRn -> ForeignExport DocNameI
|
| 840 | 845 | renameForE (CExport _ spec) = CExport noExtField spec
|
| ... | ... | @@ -42,7 +42,7 @@ import Data.IORef |
| 42 | 42 | import Data.Map (Map)
|
| 43 | 43 | import Data.Version
|
| 44 | 44 | import Data.Word
|
| 45 | -import GHC hiding (NoLink)
|
|
| 45 | +import GHC hiding (Header, NoLink)
|
|
| 46 | 46 | import GHC.Data.FastMutInt
|
| 47 | 47 | import GHC.Data.FastString
|
| 48 | 48 | import GHC.Iface.Binary (getWithUserData, putSymbolTable)
|
| ... | ... | @@ -51,7 +51,7 @@ import Data.Data (Data) |
| 51 | 51 | import Data.Map (Map)
|
| 52 | 52 | import qualified Data.Map as Map
|
| 53 | 53 | import qualified Data.Set as Set
|
| 54 | -import GHC
|
|
| 54 | +import GHC hiding (Header)
|
|
| 55 | 55 | import GHC.Data.BooleanFormula (BooleanFormula)
|
| 56 | 56 | import GHC.Driver.Session (Language)
|
| 57 | 57 | import qualified GHC.LanguageExtensions as LangExt
|
| ... | ... | @@ -833,6 +833,7 @@ type instance Anno (HsSigType DocNameI) = SrcSpanAnnA |
| 833 | 833 | type instance Anno (BooleanFormula DocNameI) = SrcSpanAnnL
|
| 834 | 834 | type instance Anno (OverlapMode DocNameI) = EpAnn AnnPragma
|
| 835 | 835 | type instance Anno (CType DocNameI) = EpAnn AnnPragma
|
| 836 | +type instance Anno (Header DocNameI) = EpAnn AnnPragma
|
|
| 836 | 837 | |
| 837 | 838 | type XRecCond a =
|
| 838 | 839 | ( XParTy a ~ (EpToken "(", EpToken ")")
|
| ... | ... | @@ -934,6 +935,9 @@ type instance XXCCallTarget DocNameI = DataConCantHappen |
| 934 | 935 | type instance XCType DocNameI = NoExtField
|
| 935 | 936 | type instance XXCType DocNameI = DataConCantHappen
|
| 936 | 937 | |
| 938 | +type instance XHeader DocNameI = NoExtField
|
|
| 939 | +type instance XXHeader DocNameI = DataConCantHappen
|
|
| 940 | + |
|
| 937 | 941 | type instance XConDeclGADT DocNameI = NoExtField
|
| 938 | 942 | type instance XConDeclH98 DocNameI = NoExtField
|
| 939 | 943 | type instance XXConDecl DocNameI = DataConCantHappen
|