X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FhsSyn%2FConvert.lhs;h=fc5f897afb3e3a3719d965f9812f0255e8f84317;hp=b87c18c56dfd60c332bc83486a8b4a597a6d92f0;hb=83d563cb9ede0ba792836e529b1e2929db926355;hpb=74fadd40c435b13da51695f0ec490e03ccce56e4 diff --git a/compiler/hsSyn/Convert.lhs b/compiler/hsSyn/Convert.lhs index b87c18c..fc5f897 100644 --- a/compiler/hsSyn/Convert.lhs +++ b/compiler/hsSyn/Convert.lhs @@ -7,7 +7,8 @@ This module converts Template Haskell syntax into HsSyn \begin{code} module Convert( convertToHsExpr, convertToPat, convertToHsDecls, - convertToHsType, thRdrNameGuesses ) where + convertToHsType, convertToHsPred, + thRdrNameGuesses ) where import HsSyn as Hs import qualified Class @@ -19,6 +20,7 @@ import qualified OccName import OccName import SrcLoc import Type +import Coercion import TysWiredIn import BasicTypes as Hs import ForeignCall @@ -57,6 +59,10 @@ convertToHsType :: SrcSpan -> TH.Type -> Either Message (LHsType RdrName) convertToHsType loc t = initCvt loc $ wrapMsg "type" t $ cvtType t +convertToHsPred :: SrcSpan -> TH.Pred -> Either Message (LHsPred RdrName) +convertToHsPred loc t + = initCvt loc $ wrapMsg "type" t $ cvtPred t + ------------------------------------------------------------------- newtype CvtM a = CvtM { unCvtM :: SrcSpan -> Either Message a } -- Push down the source location; @@ -369,6 +375,7 @@ cvtForD (ImportF callconv safety from nm ty) Unsafe -> PlayRisky Safe -> PlaySafe False Threadsafe -> PlaySafe True + Interruptible -> PlayInterruptible cvtForD (ExportF callconv as nm ty) = do { nm' <- vNameL nm @@ -394,20 +401,27 @@ cvtPragmaD (SpecialiseP nm ty opt_ispec) ; ty' <- cvtType ty ; return $ SpecSig nm' ty' (cvtInlineSpec opt_ispec) } -cvtInlineSpec :: Maybe TH.InlineSpec -> Hs.InlineSpec +cvtInlineSpec :: Maybe TH.InlineSpec -> Hs.InlinePragma cvtInlineSpec Nothing - = defaultInlineSpec + = defaultInlinePragma cvtInlineSpec (Just (TH.InlineSpec inline conlike opt_activation)) - = mkInlineSpec opt_activation' matchinfo inline + = InlinePragma { inl_act = opt_activation', inl_rule = matchinfo + , inl_inline = inl_spec, inl_sat = Nothing } where matchinfo = cvtRuleMatchInfo conlike - opt_activation' = fmap cvtActivation opt_activation + opt_activation' = cvtActivation opt_activation cvtRuleMatchInfo False = FunLike cvtRuleMatchInfo True = ConLike - cvtActivation (False, phase) = ActiveBefore phase - cvtActivation (True , phase) = ActiveAfter phase + inl_spec | inline = Inline + | otherwise = NoInline + -- Currently we have no way to say Inlinable + + cvtActivation Nothing | inline = AlwaysActive + | otherwise = NeverActive + cvtActivation (Just (False, phase)) = ActiveBefore phase + cvtActivation (Just (True , phase)) = ActiveAfter phase --------------------------------------------------- -- Declarations @@ -568,10 +582,16 @@ if it isn't a literal string allCharLs :: [TH.Exp] -> Maybe String -- Note [Converting strings] -allCharLs (LitE (CharL c) : xs) - | Just cs <- allCharLs xs = Just (c:cs) -allCharLs [] = Just [] -allCharLs _ = Nothing +-- NB: only fire up this setup for a non-empty list, else +-- there's a danger of returning "" for [] :: [Int]! +allCharLs xs + = case xs of + LitE (CharL c) : ys -> go [c] ys + _ -> Nothing + where + go cs [] = Just (reverse cs) + go cs (LitE (CharL c) : ys) = go (c:cs) ys + go _ _ = Nothing cvtLit :: Lit -> CvtM HsLit cvtLit (IntPrimL i) = do { force i; return $ HsIntPrim i } @@ -579,11 +599,12 @@ cvtLit (WordPrimL w) = do { force w; return $ HsWordPrim w } cvtLit (FloatPrimL f) = do { force f; return $ HsFloatPrim f } cvtLit (DoublePrimL f) = do { force f; return $ HsDoublePrim f } cvtLit (CharL c) = do { force c; return $ HsChar c } -cvtLit (StringL s) - = do { let { s' = mkFastString s } - ; force s' - ; return $ HsString s' - } +cvtLit (StringL s) = do { let { s' = mkFastString s } + ; force s' + ; return $ HsString s' } +cvtLit (StringPrimL s) = do { let { s' = mkFastString s } + ; force s' + ; return $ HsStringPrim s' } cvtLit _ = panic "Convert.cvtLit: Unexpected literal" -- cvtLit should not be called on IntegerL, RationalL -- That precondition is established right here in @@ -631,7 +652,7 @@ cvtTvs tvs = mapM cvt_tv tvs cvt_tv :: TH.TyVarBndr -> CvtM (LHsTyVarBndr RdrName) cvt_tv (TH.PlainTV nm) = do { nm' <- tName nm - ; returnL $ UserTyVar nm' + ; returnL $ UserTyVar nm' placeHolderKind } cvt_tv (TH.KindedTV nm ki) = do { nm' <- tName nm @@ -834,14 +855,7 @@ isBuiltInOcc ctxt_ns occ mk_uniq_occ :: OccName.NameSpace -> String -> Int# -> OccName.OccName mk_uniq_occ ns occ uniq = OccName.mkOccName ns (occ ++ '[' : shows (mk_uniq uniq) "]") - -- The idea here is to make a name that - -- a) the user could not possibly write, and - -- b) cannot clash with another NameU - -- Previously I generated an Exact RdrName with mkInternalName. - -- This works fine for local binders, but does not work at all for - -- top-level binders, which must have External Names, since they are - -- rapidly baked into data constructors and the like. Baling out - -- and generating an unqualified RdrName here is the simple solution + -- See Note [Unique OccNames from Template Haskell] -- The packing and unpacking is rather turgid :-( mk_occ :: OccName.NameSpace -> String -> OccName.OccName @@ -862,3 +876,17 @@ mk_uniq :: Int# -> Unique mk_uniq u = mkUniqueGrimily (I# u) \end{code} +Note [Unique OccNames from Template Haskell] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +The idea here is to make a name that + a) the user could not possibly write (it has a "[" + and letters or digits from the unique) + b) cannot clash with another NameU +Previously I generated an Exact RdrName with mkInternalName. This +works fine for local binders, but does not work at all for top-level +binders, which must have External Names, since they are rapidly baked +into data constructors and the like. Baling out and generating an +unqualified RdrName here is the simple solution + +See also Note [Suppressing uniques in OccNames] in OccName, which +suppresses the unique when opt_SuppressUniques is on.