From: Adam Megacz Date: Tue, 14 Jun 2011 18:50:10 +0000 (-0700) Subject: merge upstream X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=7e95df790b34e11d7308e43dab0a7175b69b70fc merge upstream --- 7e95df790b34e11d7308e43dab0a7175b69b70fc diff --cc compiler/deSugar/Desugar.lhs index 2e51823,af2db36..9b48cce --- a/compiler/deSugar/Desugar.lhs +++ b/compiler/deSugar/Desugar.lhs @@@ -207,117 -116,36 +207,117 @@@ deSugar hsc_en ; case mb_res of { Nothing -> return (msgs, Nothing) ; - Just (ds_ev_binds, all_prs, all_rules, ds_vects, ds_fords,ds_hpc_info, modBreaks - Just (ds_ev_binds, all_prs, all_rules, vects0, ds_fords, ds_hpc_info, modBreaks) -> do ++ Just (ds_ev_binds, all_prs, all_rules, vects0, ds_fords, ds_hpc_info, modBreaks + , hetmet_brak, hetmet_esc + , hetmet_flatten + , hetmet_unflatten + , hetmet_flattened_id + , hetmet_PGArrow + , hetmet_PGArrow_unit + , hetmet_PGArrow_tensor + , hetmet_PGArrow_exponent + , hetmet_pga_id + , hetmet_pga_comp + , hetmet_pga_first + , hetmet_pga_second + , hetmet_pga_cancell + , hetmet_pga_cancelr + , hetmet_pga_uncancell + , hetmet_pga_uncancelr + , hetmet_pga_assoc + , hetmet_pga_unassoc + , hetmet_pga_copy + , hetmet_pga_drop + , hetmet_pga_swap + , hetmet_pga_applyl + , hetmet_pga_applyr + , hetmet_pga_curryl + , hetmet_pga_curryr + , hetmet_pga_loopl + , hetmet_pga_loopr + ) -> do - { -- Add export flags to bindings - keep_alive <- readIORef keep_var - ; let (rules_for_locals, rules_for_imps) + { -- Add export flags to bindings + keep_alive <- readIORef keep_var + ; let (rules_for_locals, rules_for_imps) = partition isLocalRule all_rules final_prs = addExportFlagsAndRules target - export_set keep_alive rules_for_locals (fromOL all_prs) + export_set keep_alive rules_for_locals (fromOL all_prs) - final_pgm = combineEvBinds ds_ev_binds final_prs + final_pgm = let comb = combineEvBinds ds_ev_binds final_prs + in if dopt Opt_F_simpleopt_before_flatten dflags + then comb + else simplifyBinds comb - -- Notice that we put the whole lot in a big Rec, even the foreign binds - -- When compiling PrelFloat, which defines data Float = F# Float# - -- we want F# to be in scope in the foreign marshalling code! - -- You might think it doesn't matter, but the simplifier brings all top-level - -- things into the in-scope set before simplifying; so we get no unfolding for F#! - - -- Lint result if necessary, and print - ; dumpIfSet_dyn dflags Opt_D_dump_ds "Desugared, before opt" $ - (vcat [ pprCoreBindings final_pgm - , pprRules rules_for_imps ]) + -- Notice that we put the whole lot in a big Rec, even the foreign binds + -- When compiling PrelFloat, which defines data Float = F# Float# + -- we want F# to be in scope in the foreign marshalling code! + -- You might think it doesn't matter, but the simplifier brings all top-level + -- things into the in-scope set before simplifying; so we get no unfolding for F#! - -- Lint result if necessary, and print - ; dumpIfSet_dyn dflags Opt_D_dump_ds "Desugared, before opt" $ - (vcat [ pprCoreBindings final_pgm - , pprRules rules_for_imps ]) + ; (final_pgm', rules_for_imps') <- if dopt Opt_F_simpleopt_before_flatten dflags + then simpleOptPgm dflags final_pgm rules_for_imps + else return (final_pgm, rules_for_imps) + + ; ds_binds <- if dopt Opt_F_coqpass dflags + then do { us <- mkSplitUniqSupply '~' + ; let do_flatten = dopt Opt_F_flatten dflags + ; let do_skolemize = dopt Opt_F_skolemize dflags + ; return (coqPassCoreToCore + do_flatten + do_skolemize + hetmet_brak + hetmet_esc + hetmet_flatten + hetmet_unflatten + hetmet_flattened_id + us + final_pgm' + hetmet_PGArrow + hetmet_PGArrow_unit + hetmet_PGArrow_tensor + hetmet_PGArrow_exponent + hetmet_pga_id + hetmet_pga_comp + hetmet_pga_first + hetmet_pga_second + hetmet_pga_cancell + hetmet_pga_cancelr + hetmet_pga_uncancell + hetmet_pga_uncancelr + hetmet_pga_assoc + hetmet_pga_unassoc + hetmet_pga_copy + hetmet_pga_drop + hetmet_pga_swap + hetmet_pga_applyl + hetmet_pga_applyr + hetmet_pga_curryl + hetmet_pga_curryr + hetmet_pga_loopl + hetmet_pga_loopr + ) + } + else return final_pgm + + ; (ds_binds', ds_rules_for_imps) <- if dopt Opt_F_simpleopt_before_flatten dflags + then return (ds_binds, rules_for_imps') + else simpleOptPgm dflags ds_binds rules_for_imps' + -- The simpleOptPgm gets rid of type + -- bindings plus any stupid dead code + + ; dumpIfSet_dyn dflags Opt_D_dump_proofs "Coq Pass Output" $ text $ coqPassCoreToString ds_binds' + + ; dumpIfSet_dyn dflags Opt_D_coqpass "After Coq Pass" (text $ showSDoc $ pprCoreBindings ds_binds') - ; endPass dflags CoreDesugar ds_binds' ds_rules_for_imps + ; (ds_binds, ds_rules_for_imps, ds_vects) + <- simpleOptPgm dflags final_pgm rules_for_imps vects0 + -- The simpleOptPgm gets rid of type + -- bindings plus any stupid dead code + + ; endPass dflags CoreDesugar ds_binds ds_rules_for_imps ; let used_names = mkUsedNames tcg_env - ; deps <- mkDependencies tcg_env + ; deps <- mkDependencies tcg_env ; let mod_guts = ModGuts { mg_module = mod, @@@ -566,49 -394,11 +566,44 @@@ the rule is precisly to optimise them \begin{code} dsVect :: LVectDecl Id -> DsM CoreVect - dsVect (L loc (HsVect v rhs)) + dsVect (L loc (HsVect (L _ v) rhs)) = putSrcSpanDs loc $ do { rhs' <- fmapMaybeM dsLExpr rhs - ; return $ Vect (unLoc v) rhs' + ; return $ Vect v rhs' } - -- dsVect (L loc (HsVect v Nothing)) - -- = return $ Vect v Nothing - -- dsVect (L loc (HsVect v (Just rhs))) - -- = putSrcSpanDs loc $ - -- do { rhs' <- dsLExpr rhs - -- ; return $ Vect v (Just rhs') - -- } + dsVect (L _loc (HsNoVect (L _ v))) + = return $ NoVect v \end{code} + + + +\begin{code} +-- +-- Simplification routines run before the flattener. We can't use +-- simpleOptPgm -- it doesn't preserve the order of subexpressions or +-- let-binding groups. +-- +simplify :: Expr CoreBndr -> Expr CoreBndr +simplify (Var v) = Var v +simplify (App e1 e2) = App (simplify e1) (simplify e2) +simplify (Lit lit) = Lit lit +simplify (Note note e) = Note note (simplify e) +simplify (Cast e co) = if eqType (fst $ unPair $ coercionKind co) (snd $ unPair $ coercionKind co) + then simplify e + else Cast (simplify e) co +simplify (Lam v e) = Lam v (simplify e) +simplify (Case e b ty as) = Case (simplify e) b ty (map (\(a,b,e) -> (a,b,simplify e)) as) +simplify (Let bind body) = foldr Let (simplify body) (simplifyBind bind) +simplify (Type t) = Type t +simplify (Coercion co) = Coercion co + +simplifyBind :: Bind CoreBndr -> [Bind CoreBndr] +simplifyBind (NonRec b e) = [NonRec b (simplify e)] +simplifyBind (Rec []) = [] +simplifyBind (Rec (rbs@((b,e):rbs'))) = + if or $ map (\x -> elemUFM x (exprFreeIds e)) (map fst rbs) + then [Rec (map (\(v,e) -> (v,simplify e)) rbs)] + else (NonRec b (simplify e)):(simplifyBind $ Rec rbs') + +simplifyBinds = concatMap simplifyBind +\end{code} diff --cc compiler/parser/Lexer.x index 4ca0282,43a4004..c9b2e1c --- a/compiler/parser/Lexer.x +++ b/compiler/parser/Lexer.x @@@ -1605,20 -1594,13 +1612,20 @@@ getExts = P $ \s -> POk s (extsBitmap s setExts :: (Int -> Int) -> P () setExts f = P $ \s -> POk s{ extsBitmap = f (extsBitmap s) } () - setSrcLoc :: SrcLoc -> P () + setSrcLoc :: RealSrcLoc -> P () setSrcLoc new_loc = P $ \s -> POk s{loc=new_loc} () +incrBracketDepth :: P () +incrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (code_type_bracket_depth s)+1}) () +decrBracketDepth :: P () +decrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (code_type_bracket_depth s)-1}) () +getParserBrakDepth :: P Int +getParserBrakDepth = P $ \s -> POk s (code_type_bracket_depth s) + - getSrcLoc :: P SrcLoc + getSrcLoc :: P RealSrcLoc getSrcLoc = P $ \s@(PState{ loc=loc }) -> POk s loc - setLastToken :: SrcSpan -> Int -> P () + setLastToken :: RealSrcSpan -> Int -> P () setLastToken loc len = P $ \s -> POk s { last_loc=loc, last_len=len @@@ -1894,11 -1872,10 +1901,11 @@@ mkPState flags buf loc lex_state = [bol, 0], alr_pending_implicit_tokens = [], alr_next_token = Nothing, - alr_last_loc = noSrcSpan, + alr_last_loc = alrInitialLoc (fsLit ""), alr_context = [], alr_expecting_ocurly = Nothing, - alr_justClosedExplicitLetBlock = False + alr_justClosedExplicitLetBlock = False, + code_type_bracket_depth = 0 } where bitmap = ffiBit `setBitIf` xopt Opt_ForeignFunctionInterface flags diff --cc compiler/parser/Parser.y.pp index a71323f,b663ac2..1a847ec --- a/compiler/parser/Parser.y.pp +++ b/compiler/parser/Parser.y.pp @@@ -39,11 -39,9 +39,9 @@@ import Type ( funTyCon import ForeignCall ( Safety(..), CExportSpec(..), CLabelString, CCallConv(..), CCallTarget(..), defaultCCallConv ) -import OccName ( varName, dataName, tcClsName, tvName ) +import OccName ( varName, varNameDepth, dataName, tcClsName, tvName ) import DataCon ( DataCon, dataConName ) - import SrcLoc ( Located(..), unLoc, getLoc, noLoc, combineSrcSpans, - SrcSpan, combineLocs, srcLocFile, - mkSrcLoc, mkSrcSpan ) + import SrcLoc import Module import StaticFlags ( opt_SccProfilingOn, opt_Hpc ) import Type ( Kind, liftedTypeKind, unliftedTypeKind ) @@@ -1269,12 -1262,8 +1269,12 @@@ quasiquote :: { Located (HsQuasiQuote R : TH_QUASIQUOTE { let { loc = getLoc $1 ; ITquasiQuote (quoter, quote, quoteSpan) = unLoc $1 ; quoterId = mkUnqual varName quoter } - in L1 (mkHsQuasiQuote quoterId quoteSpan quote) } + in L1 (mkHsQuasiQuote quoterId (RealSrcSpan quoteSpan) quote) } +incdepth :: { Located () } : {% do { incrBracketDepth ; return $ noLoc () } } +decdepth :: { Located () } : {% do { decrBracketDepth ; return $ noLoc () } } + + exp :: { LHsExpr RdrName } : infixexp '::' sigtype { LL $ ExprWithTySig $1 $3 } | infixexp '-<' exp { LL $ HsArrApp $1 $3 placeHolderType HsFirstOrderApp True } diff --cc compiler/prelude/PrelNames.lhs index f84f0a4,d226cbe..a2c81de --- a/compiler/prelude/PrelNames.lhs +++ b/compiler/prelude/PrelNames.lhs @@@ -304,12 -276,9 +304,12 @@@ gHC_PRIM, gHC_TYPES, gHC_UNIT, gHC_ORDE gHC_MAGIC, gHC_CLASSES, gHC_BASE, gHC_ENUM, gHC_CSTRING, gHC_SHOW, gHC_READ, gHC_NUM, gHC_INTEGER, gHC_INTEGER_TYPE, gHC_LIST, + gHC_HETMET_CODETYPES, + gHC_HETMET_PRIVATE, + gHC_HETMET_GARROW, gHC_TUPLE, dATA_TUPLE, dATA_EITHER, dATA_STRING, dATA_FOLDABLE, dATA_TRAVERSABLE, - gHC_PACK, gHC_CONC, gHC_IO, gHC_IO_Exception, - gHC_ST, gHC_ARR, gHC_STABLE, gHC_ADDR, gHC_PTR, gHC_ERR, gHC_REAL, + gHC_CONC, gHC_IO, gHC_IO_Exception, + gHC_ST, gHC_ARR, gHC_STABLE, gHC_PTR, gHC_ERR, gHC_REAL, gHC_FLOAT, gHC_TOP_HANDLER, sYSTEM_IO, dYNAMIC, tYPEABLE, gENERICS, dOTNET, rEAD_PREC, lEX, gHC_INT, gHC_WORD, mONAD, mONAD_FIX, mONAD_GROUP, mONAD_ZIP, aRROW, cONTROL_APPLICATIVE, gHC_DESUGAR, rANDOM, gHC_EXTS,